Le 27/12/2013 19:10, Claude Pache a écrit :
There is still the issue of potential libraries that produce
arraylikes that don't inherit from a built-in arraylike prototype:
those won't benefit from your polyfill without changing their
inheritance strategy.
I don't understand the expression "inherit from a built-in arraylike
prototype". Could you explain this further?
(I don't know whether it's a common issue.)
I think any use case involving libraries can be solved.
In an ES6 world, a library would make Array.from work via setting an
appropriate @@iterator on the objects it generates.
Based on what I suggested (internalize iterators in Array.from code for
polyfills), the ES5 equivalent is to override Array.from as such:
````js
(function(){
var nativeArrayFrom = Array.from;
Array.from = function(x){
if(/*x is of my library type*/){
/* generate an equivalent array using the traversal logic
that would be used for its @@iterator in ES6
*/
}
else{
return nativeArrayFrom(x);
}
}
})()
````
Granted, it's not super elegant solution, but it does work. The overhead
becomes significant only in the degenerate cases where dozens of
libraries override Array.from.
David
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss