Enumerability is still important (was: Re: Object.define ==> Object.mixin??)
herby at mailbox.sk
Tue Dec 11 10:42:37 PST 2012
Allen Wirfs-Brock wrote:
> 3) I don't see any reason that it should be restricted to enumerable
> properties. If the intend is to deprecate enumerable along with for-in
> then we should be adding new functionality that is sensitive to the
> state of the enumerable attribute.
Well, I had a real-world issue in which enumerability (and
non-enumerability of methods) was still important.
there were issues, which failed with jQuery.ajax call. The object
passed as options parameter was a HashedCollection, which mimicked JS
object (keys as strings etc.), but the methods inherited via prototype
striked back. JQuery read all properties (own as well as inherited),
which makes sense, one can have templates and Object.create() from them,
Object.defineProperty also honours inherited properties.
But some of the inherited properties make this fail or eat 100%CPU.
Similar problem appeared with jQuery.css call (though I can't find an
issue, it was probably only on the mailinglist).
The fix was to make methods non-enumerable.
Now, jQuery takes enumerability (and I think not only jQuery does this)
as a rough equivalent of "published" so it treats enumerables as visible
part of object and non-enumerables are ignored for
If enumerable is to be deprecated, how should this be solved? If jQuery
stops to honour inherited attributes, it would break Object.create()d
data passed in. If not, one cannot safely pass in instance of the class
with method, because methods will be included in the properties.
More information about the es-discuss