Must built-in prototypes also be valid instances? (Was: Why DataView.prototype object's [[Class]] is "Object"?)

Norbert Lindenberg ecmascript at norbertlindenberg.com
Mon Oct 1 14:44:23 PDT 2012


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.

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.

3) The state mentioned in 2) is modifiable.

True for some ES5 objects (Array, Date, RegExp), not true for ES Internationalization objects. The discussion seems to conclude that modifiable prototype objects are a bad idea.

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.

5) BuiltIn.prototype instanceof BuiltIn evaluates to true.

False for ES5 objects and ES Internationalization objects. The ES5 spec for instanceof relies on 4).

Any observable features I missed?

Norbert



More information about the es-discuss mailing list