On Nov 1, 7:06 pm, Anoop <[email protected]> wrote:
> As per the MDN documentation:
> A for...in loop does not iterate over non–enumerable properties.
> Objects created from built–in constructors like Array and Object have
> inherited non–enumerable properties from Object.prototype and
> String.protottype

Neither Objects (ECMA-262 § 15.2.2.1) or Arrays (ECMA-262 § 15.4.2.1)
inherit from String.prototype. In particular, the internal
[[Prototype]] of Object.prototype is null, so it doesn't inherit from
anything.


> that are not enumerable, such as String's indexOf
> method or Object's toString method.

Arrays inherit indexOf from Array.prototype, not String.prototype. The
built-in Object.prototype doesn't have an indexOf method, so native
objects will only have one if it is specifically added, in which case
it will be enumerable (unless ES5 features are used to make it not
enumerable, but that is unlikely on the web).


> The loop will iterate over all
> enumerable properties of the object or that it inherits from its
> constructor's proptotype

That "or" should be an "and".

> (including any which overwrite built-in
> properties).

Where a property is added to a property resolution chain that has the
same name as one further along the chain, it doesn't "overwrite" the
property, it "shaddows" it. That is, property resolution checks the
object itself, then its internal [[Prototype]], then that object's
internal [[Prototype]] and so on. It stops at the first match (or when
the end of the chain is reached).

--
Rob

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to