Suggestions for the proposed ByteArray in ES4

Brendan Eich brendan at
Thu Jan 18 10:14:51 PST 2007

On Jan 17, 2007, at 8:46 PM, Jeff Walden wrote:

> I can see arguments for some of SpiderMonkey's array iteration  
> extensions (some/every/map/filter/forEach) and for the other  
> standard ES array methods, but I can't come up with a real-world  
> use case for any of them and have thus left them off; someone else  
> can come up with them if desired.  Since most of the Array methods  
> are generic anyway, I see no reason you couldn't copy them over  
> using some Array.prototype.*.apply magic.  Beyond the methods  
> mentioned here, tho, I really don't think you need much more  
> functionality most of the time.

Note that the Array and String methods that do not constrain their | 
this| parameter's type -- most methods on Array.prototype and  
String.prototype, the exceptions are toString, toLocaleString, and  
valueOf -- are available as static methods of the same name, with a  
leading explicit |this|-object parameter: Array.indexOf(arraylike,  
value) returns -1 or the index of the first occurrence of value in  

These methods work without optimization on any array-like object (one  
having a length:uint32 property that limits non-negative integral  
property identifiers, whether dense or sparse).  So they'll work on  
ByteArray out of the box.  But it would be even more convenient if  
ByteArray instances delegated to Array.prototype (or to optimized  
versions of appropriate methods on ByteArray.prototype, or even  
fixture methods declared in class ByteArray).

Proposal: make ByteArray a subclass of Array.  ByteArray overrides  
the non-generic toString and toLocaleString methods.  Implementations  
may optimize by overriding the remaining generic methods, or delegate  
to the generic Array implementations.

> One last suggestion: ByteArray should support slice notation, with  
> the result referencing the original ByteArray (i.e., mutating the  
> result of a slice of a ByteArray modifies the original) so long as  
> the step is 1 and the slice is not a copying slice (copy = byteArray 
> [:]).

Slicing is generic, it maps onto slice(start[, stop[, step]]) and  
setSlice(value, start[, stop[, step]]) instance methods.

However, dependent slices are a bad idea; mutation via a shared  
reference is a hazard.  Are you prematurely optimizing?


More information about the Es4-discuss mailing list