Le 26/05/2012 21:08, Brendan Eich a écrit :
> David Bruant wrote:
>>> Because max-min classes are inching towards consensus, I suggest the
>>> that appropriate way to subclass the built-in constructors will be
>>> via |class extends|. eg
>>>
>>> class MyArray extends Array {
>>> someMyArrayProtoMethod () {...}
>>> constructor (tag) {
>>> super();
>>> this.tag=tag
>>> }
>>> }
>> If that's the case, then that's perfect!
>> It suffers from the same issue than <| which is that it's
>> syntax-based, so minimum cost is an ES6->ES5 compiler
>
> But that is why subclassing the DOM via __proto__ has already dug in
> as a de-facto standard:
>
> zepto.js: return isObject(value) && value.__proto__ ==
> Object.prototype
> zepto.js: // to the array. Note that `__proto__` is not supported on
> Internet
> zepto.js: dom.__proto__ = arguments.callee.prototype
"__proto__", "arguments" and "callee" on the same line. What else?
For context:
https://github.com/madrobby/zepto/blob/9c79b624b3101b70e0bbd465ea2619f4d2cd832a/src/zepto.js#L108-117
> and why IE faces pressure to support __proto__, including setting for
> DOM objects.
>
> New syntax may some day clean all this up but the short path wins and
> it'll be hard to displace. Let's be realistic. I agree we should,
> assuming classes make it, support DOM subclassing.
I'm not sure we mean the same thing when talking about subclassing. What
I mean is being able, from a constructor to create another constructor.
Instances of the latter will have the internal properties of instances
of the former (instances of SubArray are Arrays (magic 'length'),
instances of SubWeakMap are WeakMaps, instances of SubNodeList are
NodeLists, etc.).
With this definition, it's not possible to subclass the DOM
constructors, since they all throw. The DOM API itself would need to be
changed to allow subclassing.
Regardless of throwing, even if we could create a SubNodeList type, that
would be cool, but it wouldn't change the fact that
document.querySelectorAll returns a NodeList and not a SubNodeList. The
entire DOM API works this way and doesn't allow method return values to
be subclassed as far as I know. Constructors are coming (Event in DOM4
for instance), but all DOM methods still only return objects of types
defined in the DOM-related specs.
Having instances of SubNodeList is Zepto.js use case [1] and the
definition of subclassing I gave above is insufficient to fulfill it.
To subclass the DOM, ECMAScript scope isn't enough, changes on the DOM
API would be necessary too.
Depressingly enough, document.querySelectorAll calls don't even
construct objects with the dynamic NodeList.prototype value [2].
> That is good but it won't relieve DOM implementors from supporting
> __proto__.
We agree on this.
David
[1] see in zepto.js, the zepto.init function, the call the zepto.qsa
followed by "return zepto.Z(dom, selector)"
[2] https://gist.github.com/2815846
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss