On Jun 19, 2012, at 3:20 PM, Erik Arvidsson wrote:

> On Tue, Jun 19, 2012 at 1:55 PM, David Bruant <bruan...@gmail.com> wrote:
>> Le 19/06/2012 18:21, Erik Arvidsson a écrit :
>>> On Tue, Jun 19, 2012 at 6:42 AM, 程劭非 <csf...@gmail.com> wrote:
>>>> I guess we can try to push Web IDL to do this.
>>> WebIDL provides [ArrayClass] and DOM4 make NodeLists ArrayClass. This
>>> means that NodeLists have Array.prototype on its prototype chain.
>> Excellent! I hadn't heard of that.
>> 
>>> We tried to make this change in WebKit but it caused some issues,
>>> mostly on sites depending on a bug in Closure Library. The Closure bug
>>> has been fixed but the question is how many other sites out there do
>>> incorrect detection and therefore assume that anything that is an
>>> instance of Array is actually a true Array
>> I'll guess a quantity between "a lot" and "a ridiculous amount".
>> I read "if(something instanceof Array)" very often when view-sourcing
>> and they mean "Array.isArray(something)".
>> A trickier question is: will this code break the NodeLists inherit from
>> Array.prototype and that's harder to answer.
> 
> The case that broke was something like this:
> 
> if (x instanceof Array)
>  realArray.concat(x);
> 
> The problem is that concat behaves different when its argument is a
> real Array ([[Class]] is "Array").
> 
> I wonder if we could change concat in such a way that it checks the
> prototype chain too?


I touched upon this in #5 of 
http://wiki.ecmascript.org/doku.php?id=strawman:es5_internal_nominal_typing and 
in more detail in 
https://docs.google.com/document/d/1sSUtri6joyOOh23nVDfMbs1wDS7iDMDUFVVeHeRdSIw/edit?authkey=CI-FopgC
 

Basically the way to fix it is to define a well known private name property 
that concat uses to determine the kind of target container to instantiate (for 
example, its value could be the constructor to invoke to create it).

Then things like NoteList.prototype could have that property defined such as to 
produce NodeList instances.

I probably need to write up a short strawman specifically about this. 

Allen
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to