(function foo(){}).propertyIsEnumerable("prototype"): true or false?

# Jeff Walden (16 years ago)

ES3, 15.3.5.2, says the prototype property of function instances is enumerable.

ES5, 13.2 step 17, says the prototype property of function instances is not enumerable.

Was this change intentional, and if so, can someone point me to discussion of the change? I don't care one way or the other, but given past paranoia over incompatible changes, this change seems somewhat gratuitous. Was this done to ease enumeration of properties on function instances, perhaps? Maybe that's enough motivation, but I don't see natural use cases for doing so.

# Mark S. Miller (16 years ago)

On Thu, Sep 3, 2009 at 7:36 PM, Jeff Walden<jwalden+es at mit.edu> wrote:

ES3, 15.3.5.2, says the prototype property of function instances is enumerable.

ES5, 13.2 step 17, says the prototype property of function instances is not enumerable.

Was this change intentional, and if so, can someone point me to discussion of the change?  I don't care one way or the other, but given past paranoia over incompatible changes, this change seems somewhat gratuitous.  Was this done to ease enumeration of properties on function instances, perhaps?  Maybe that's enough motivation, but I don't see natural use cases for doing so.

I don't remember discussing this. But if we had, our general principle is that we first need to be compatible with the cross-browser web, and only second with the text of the ES3 standard. A bit of testing reveals that 'prototype' is enumerable on Firefox and not on Safari or Opera. Someone with Windows should test IE. If it isn't enumerable on IE, then the governing principle would be the three of four browsers heuristic. If it is, then since the four browsers are split, either decision is compatible with the cross browser web so we should codify whatever seems most sensible.

# Jeff Walden (16 years ago)

On 3.9.09 20:04 , Mark S. Miller wrote:

I don't remember discussing this. But if we had, our general principle is that we first need to be compatible with the cross-browser web, and only second with the text of the ES3 standard. A bit of testing reveals that 'prototype' is enumerable on Firefox and not on Safari or Opera. Someone with Windows should test IE. If it isn't enumerable on IE, then the governing principle would be the three of four browsers heuristic. If it is, then since the four browsers are split, either decision is compatible with the cross browser web so we should codify whatever seems most sensible.

Chrome: enumerable Firefox: enumerable IE: not enumerable Safari: not enumerable Opera: not enumerable

I doubt there's serious reliance on enumerability or lack thereof of prototype on functions, given this. The results are semi-inconclusive, but given the late date that's a good vote for leaving ES5 as-is, with the incompatible change, in my book. I'll assume such unless others think this is worth more discussion.

# Allen Wirfs-Brock (16 years ago)

ES3, 15.3.5.2, says the prototype property of function instances is enumerable. ES5, 13.2 step 17, says the prototype property of function instances is not enumerable.

ES5, 15.3.5.2 also says non-enumerable so at least it is internally consistent. I don't recall this specific change but tomorrow I'll look at some back drafts and see if I can identify when/why the change was made. Non-enumerable seems like the preferable value but I don't think we would have made an incompatible change unless we both thought the old definition was "wrong" and the actual web was inconsistent. Since Chrome wasn't yet around when some of these decisions were made 3 out of 4 major browser implementations were probably non-enumerable at the time.

# Brendan Eich (16 years ago)

On Sep 3, 2009, at 8:48 PM, Allen Wirfs-Brock wrote:

ES3, 15.3.5.2, says the prototype property of function instances is
enumerable. ES5, 13.2 step 17, says the prototype property of function
instances is not enumerable.

ES5, 15.3.5.2 also says non-enumerable so at least it is internally
consistent. I don't recall this specific change but tomorrow I'll look at some
back drafts and see if I can identify when/why the change was made. Non-enumerable seems like the preferable value but I don't think we
would have made an incompatible change unless we both thought the
old definition was "wrong" and the actual web was inconsistent.
Since Chrome wasn't yet around when some of these decisions were
made 3 out of 4 major browser implementations were probably non- enumerable at the time.

Not something I noticed either, but it gets rid of an annoying
difference between built-in constructors and user-defined functions:

js> for(i in Date)print(i)

js> function MyDate(){}

js> for(i in MyDate)print(i)

prototype

I hope it doesn't break anything on the web. It could, because using
for-in to inspect properties and extend base objects with copies of
them is standard practice (Doug's "Swiss inheritance", search for
"Swiss" in www.cosmik.com/aa-october99/stan_freberg.html).

# P T Withington (16 years ago)

On 2009-09-04, at 13:24, Brendan Eich wrote:

I hope it doesn't break anything on the web. It could, because using
for-in to inspect properties and extend base objects with copies of
them is standard practice (Doug's "Swiss inheritance", search for
"Swiss" in www.cosmik.com/aa-october99/stan_freberg.html).

One small datapoint: OpenLaszlo does not expect enumerability of
function prototypes. We learned by trial and error that browsers
varied and work around that for both inspecting and extending.

# Allen Wirfs-Brock (16 years ago)

I did some digging and I can't find any specific record of this decisions but it was probably briefly discussed at the Sept. 2008 TC39 meeting in Redmond as the change first appears in a set of changes prepared by Mark Miller that are labeled "post-redmond".

I think this is a good change that should stand as is.

Given that, there is variance between IE and FF, and also between FF/Chrome and Safari/Opera it seems very unlikely that any interoperable code depends upon this enumerability, one way or another.

It should however be listed Annex E.