Norbert Lindenberg wrote:
It might be useful to list all the observable features to which "valid instance
of" might lead for a built-in BuiltIn.prototype, and check whether we want them for
new built-ins:
1) Object.prototype.toString.call(BuiltIn.prototype) returns "[object BuiltIn]".
True for ES5 objects, currently not true for ES Internationalization objects.
Discussion so far inconclusive.
Fair enough.
2) BuiltIn.prototype has state that lets BuiltIn methods successfully operate
on the object, at least as long as they don't modify the state.
True for ES5 objects, currently also true for ES Internationalization objects.
This means Intl.Collator.prototype can be used as a Collator with default
properties, which applications might find useful. Discussion so far
inconclusive.
Mark has a conclusion: don't hide mutable state behind accessors in a
prototype. The reason is that Object.freeze can't freeze such state. Is
Intl.Collator.prototype's state hidden that way, or exposed to
Object.freeze?
3) The state mentioned in 2) is modifiable.
True for some ES5 objects (Array, Date, RegExp),
Don't forget Object :-P.
not true for ES Internationalization objects. The discussion seems to
conclude that modifiable prototype objects are a bad idea.
I'm not sure -- I would say the known problem is hidden (to
Object.freeze) mutable state, not data properties such as
RegExp.lastIndex. Mark should confirm.
4) Object.getPrototypeOf(BuiltIn.prototype) returns BuiltIn.prototype.
False for ES5 objects and ES Internationalization objects. This would lead to
infinite loops when looking up properties that don't exist, and we probably
don't want that.
Yes, this makes no sense, not a goal in any scenario.
5) BuiltIn.prototype instanceof BuiltIn evaluates to true.
False for ES5 objects and ES Internationalization objects. The ES5 spec for
instanceof relies on 4).]]
Indeed this cannot be true given that o instanceof C always gets o's
[[Prototype]] before matching against C.prototype -- always hops "one up
the chain".
Any observable features I missed?
I think that's it. I hope so!
/be
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss