Prev: Dynamicly add dropdown lists to a form populated with php/mysql query
Next: MSXML HTTP translates response status code 204 to 1223
From: abozhilov on 12 Sep 2009 13:20 I have another question about delete and internal [[Delete]]. function Foo(){} Foo.prototype.a = {}; var bar = new Foo(); alert(delete bar.a); //true alert(bar.a); //[object Object] 1. Assigned to bar reference to object. That object doesn't have `a` property in object who referred `bar`. 2. Delete `a` property. 3. Get value of `a` property. In point 2, when be call [[Delete]] internal method of `object` who `bar` referred. JavaScript will be call [[HasProperty]] method of that `object`? In this case how JavaScript knows about that property? If calling [[HasProperty]] he make lookup in prototype chain. In ECMA3 i see only [[HasProperty]], doesn't exsist internal method who don't lookup in prototype chain. Thanks for responses!
From: kangax on 12 Sep 2009 13:55 abozhilov wrote: > I have another question about delete and internal [[Delete]]. > > function Foo(){} > Foo.prototype.a = {}; > > var bar = new Foo(); > alert(delete bar.a); //true > alert(bar.a); //[object Object] > > 1. Assigned to bar reference to object. That object doesn't have `a` > property in object who referred `bar`. > 2. Delete `a` property. > 3. Get value of `a` property. > > In point 2, when be call [[Delete]] internal method of `object` who > `bar` referred. JavaScript will be call [[HasProperty]] method of that > `object`? In this case how JavaScript knows about that property? If No, [[HasProperty]] is not called. Look at step 5 in 11.4.1; it calls [[Delete]] of Reference's base object, passing it property name in question. [[Delete]] then simply returns `true` (step 2 in 8.6.2.5) since base object (`bar`, not its [[Prototype]]) doesn't have such property. The usual property lookup (i.e. [[HasProperty]]) is never performed with `delete`. > calling [[HasProperty]] he make lookup in prototype chain. In ECMA3 i > see only [[HasProperty]], doesn't exsist internal method who don't > lookup in prototype chain. There's `Object.prototype.hasOwnProperty` infamous for its lack of support in older (but not ancient) browsers, such as Safari <2.0.4. Also see <http://pointedears.de/scripts/test/es-matrix/> (can't link to particular table row there). [...] -- kangax
From: abozhilov on 12 Sep 2009 14:30 On Sep 12, 8:55 pm, kangax <kan...(a)gmail.com> wrote: > No, [[HasProperty]] is not called. Look at step 5 in 11.4.1; it calls > [[Delete]] of Reference's base object, passing it property name in > question. [[Delete]] then simply returns `true` (step 2 in 8.6.2.5) > since base object (`bar`, not its [[Prototype]]) doesn't have such property. > > The usual property lookup (i.e. [[HasProperty]]) is never performed with > `delete`. Yes, delete isn't call [[HasProperty]] explicit. But when call [[Delete]] see 8.6.2.5: 1. If O doesn't have a property with name P, return true. My question is, how JavaScript know for existence on that property? > > [[HasProperty]] make lookup in prototype chain. > There's `Object.prototype.hasOwnProperty` infamous for its lack of > support in older (but not ancient) browsers, such as Safari <2.0.4. Also > see <http://pointedears.de/scripts/test/es-matrix/> (can't link to > particular table row there). Mmm this is interesting. Thank you. But why in specification isn't have internal method who's works like `hasOwnProperty`? Maybe when call [[Delete]] JavaScript engine use something like `hasOwnProperty'.
From: John G Harris on 12 Sep 2009 14:43 On Sat, 12 Sep 2009 at 10:20:43, in comp.lang.javascript, abozhilov wrote: >I have another question about delete and internal [[Delete]]. > >function Foo(){} >Foo.prototype.a = {}; > >var bar = new Foo(); >alert(delete bar.a); //true >alert(bar.a); //[object Object] > >1. Assigned to bar reference to object. That object doesn't have `a` >property in object who referred `bar`. >2. Delete `a` property. >3. Get value of `a` property. > >In point 2, when be call [[Delete]] internal method of `object` who >`bar` referred. JavaScript will be call [[HasProperty]] method of that >`object`? In this case how JavaScript knows about that property? If >calling [[HasProperty]] he make lookup in prototype chain. In ECMA3 i >see only [[HasProperty]], doesn't exsist internal method who don't >lookup in prototype chain. [[Delete]] and delete both act on the properties of the object, but not on properties in the prototype chain. delete returns false if it finds a property with the attribute DontDelete; in all other cases it returns true, including the case where there's no such property. John -- John Harris
From: kangax on 12 Sep 2009 16:10
abozhilov wrote: > On Sep 12, 8:55 pm, kangax <kan...(a)gmail.com> wrote: >> No, [[HasProperty]] is not called. Look at step 5 in 11.4.1; it calls >> [[Delete]] of Reference's base object, passing it property name in >> question. [[Delete]] then simply returns `true` (step 2 in 8.6.2.5) >> since base object (`bar`, not its [[Prototype]]) doesn't have such property. >> >> The usual property lookup (i.e. [[HasProperty]]) is never performed with >> `delete`. > > Yes, delete isn't call [[HasProperty]] explicit. But when call > [[Delete]] see 8.6.2.5: > > 1. If O doesn't have a property with name P, return true. > > My question is, how JavaScript know for existence on that property? Well, if you look at ES3 specs closely, you'll see that "property of an object" usually implies "own" property of an object. For example, section on `Object.prototype.hasOwnProperty` even explicitly says: <quote> 1. Let O be this object. 2. Call ToString(V). 3. If O doesn't have a property with the name given by Result(2), return ^^^^^^^^^^^^^^^^^^^^^^^^^ false. 4. Return true. NOTE Unlike [[HasProperty]] (8.6.2.4), this method does not consider objects in the prototype chain. </quote> (underlining is mine) And spec then uses "has property" to really mean "has *own* property" in explanations of other algorithms (such as [[Delete]]) Also note that ES5 spec (currently draft) introduces [[GetOwnProperty]], and you can see that it is this [[GetOwnProperty]] that's being used in step 1 of [[Delete]] (see 8.12.7) Ambiguity begone :) [...] -- kangax |