Re: [whatwg] Canvas: dash list API

On 23/12/12 1:01 AM, Tobie Langel wrote:
> Array-like objects which don't "inherit" from the Array object and are
> thus missing methods one would expect to find on them (forEach, join,
> etc.) is one of the biggest WTF of the Web platform. We should be doing
> whatever it takes to fix this.

I agree that that would be confusing.

I think there is some tension between having an Array subclass so that 
assignments to array elements can be type checked (and so they an be 
"notice" by the owning object) and being able to assign a new Array object.

For example it seems reasonable to be able to do:

   ctx.dashList = [5, 10];

but then after this assignment is dashList a NumberArray (or whatever we 
would call the subclass), and thus not the same object that you assigned?

   var a = [5, 10];
   ctx.dashList = a;
   a.push(20);

If the Array object were converted into a NumberArray, then the a.push() 
call wouldn't affect the dashList.


If we don't have the type checking of array elements, and also don't 
need any noticing of individual element assignments, then we can just 
have a reference to a plain Array object and look at its elements at the 
time the dash array is needed.  That could preserve the author 
expectation that after assigning a new Array object to the property you 
would get the same object back when getting the property.

Received on Saturday, 22 December 2012 14:07:49 UTC