Re: Static Array and String Generics and Host Objects (ATTN IE Team)

Garrett notes:

>> Array and String generics are useful for non-array objects.


The underscore library, Google's closure library, and I'm sure others, also implement some of the "Array" methods for Objects, iterating over key/value pairs.  I'd like to see this capability added as well.  At which point, making these methods of Array makes less sense.  

Perhaps a new global object, Collection, which could contain such static methods that worked on arrays and objects both.  Which fix the problem of the "appears to be duplicate functions" on Array / Array.prototype.

On Dec 7, 2009, at 3:42 PM, Allen Wirfs-Brock wrote:

> The "static generic" versions of these functions were discussed during the development of ES5 but nobody advocated strongly for their inclusions. 
> 
> My personal opinion is that having what appears to be duplicate functions on both Array and Array.prototype is a likely source of confusion for unsophisticated programmers and largely unnecessary for more sophisticated programmers who know how to use call.
> 
> The inadmissibly of the array functions for host object is explicitly allowed for by the ES3&5 specifications. However, I will make sure that those responsible for the IE DOM are aware of the issue.
> 
> Allen
> 
> -----Original Message-----
> From: es-discuss-bounces@mozilla.org [mailto:es-discuss-bounces@mozilla.org] On Behalf Of Maciej Stachowiak
> Sent: Monday, December 07, 2009 11:40 AM
> To: Garrett Smith
> Cc: public-script-coord@w3.org; es-discuss
> Subject: Re: Static Array and String Generics and Host Objects (ATTN IE Team)
> 
> 
> On Dec 4, 2009, at 1:48 PM, Garrett Smith wrote:
> 
>> Static Array and String Generics was an ES4 proposal[0], and is
>> implemented in Mozilla JavaScript 1.6[1].
>> 
>> What are the plans for including Array and String Generics in future
>> revision of ES?
> 
> I'm curious about this as well. We've had some requests to add these  
> to JavaScriptCore. I'd like to know if they were explicitly rejected  
> from standard ECMAScript, or might be considered for further  
> ECMAScript editions.
> 
> Would the ECMAScript standards community advise that we implement  
> these in WebKit or hold off?
> 
>  - Maciej
> 
>> 
>> There is no new syntax needed to support this. Scripts today can be
>> compatible by adding:-
>> 
>> if(!Array.slice) {
>>   Array.slice= function( arrayLike, start, end ) {
>>       return Array.prototype.slice.call( arrayLike,
>>         start||0, end||arrayLike.length);
>>   };
>> }
>> 
>> However, there is a remaining problem there: No guaranteed behavior
>> with Host object and Errors in IE. Example:
>> javascript:alert(   [].slice.call( document.childNodes ) );
>> 
>> Error in IE8: "JScript Object Expected".
>> 
>> It would be best for IE to use Native object for Host objects. That
>> way, unwanted surprises like the above error should be done away with.
>> 
>> Array and String generics are useful for non-array objects.
>> 
>> The outcome of [].slice.call() should be determinable. It is up to
>> public-script coord to define what happens when a Host object is used
>> in an Array.
>> 
>> Brendan's 7-month-old message[2] asking for IE to comment on Array
>> generics with host object, should be proactively addressed.
>> 
>> There are open bugs for Webkit[3] and Chrome[4] for implementing Array
>> generics At the time that I  filed the webkit bug, I was under the
>> impression that it was on its way to being standardized. I do not see
>> that happening.
>> 
>> Proposals:
>> 1) ES Harmony standardize Static Array and String generics
>> 2) The IE team use Native object for Host object collection
>> 
>> [0]http://wiki.ecmascript.org/doku.php?id=proposals:static_generics
>> [1]https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Arrays 
>> #Working_with_Array-like_objects
>> [2]https://mail.mozilla.org/pipermail/es-discuss/2009-May/009317.html
>> [3]https://bugs.webkit.org/show_bug.cgi?id=20261
>> [4]http://code.google.com/p/v8/issues/detail?id=308
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

Patrick Mueller - http://muellerware.org/

Received on Wednesday, 9 December 2009 13:54:20 UTC