Can an Array have array indexed accessor properties and other curiosities??
zen at zenpsycho.com
Fri Feb 13 19:12:49 PST 2009
> 1) It's disallowed, Array instances can't have own accessor properties with
> array index names. (and since Array.prototype is an Array instance it can't
> either. An array instance could only inherit an accessor property with an
> array index name from Object.prototype)
> My preference is #1. Accessor properties are new to the standard and we get
> to decide where they are and aren't allowed. ...
Arrays already have a "magical" length property. may as well make
indexes "magic" as well. As a user, I can't think of any particular
use for making certain array indexes read only.
> Here's another one. What happens if the length field is set [[Writable]]:
> false and an attempt is subsequently make to define an array indexed
> property (using either [[Put]] or Object.defineProperty) whose name is >=
> than length? I suggest it fails (silently or not depending upon the Throw
I like this. It means you can make essentially fixed length arrays.
Perhaps there is even room for implementation optimisation here if the
user does this?
> What happens if the length is explicitly reduced such that an array indexed
> property that is [[Configurable]]: false would be deleted by the ES3 array
> [[Put]] algorithm? Alternatives:
> 1) The undeletable property is left undisturbed. (This
> tosses out the ES3 invariant that length is > than the name of any array
> indexed own properties.
> 2) The redefinition of length fails (silently or not
> depending upon the Throw parameter).
> My preference is #1. #2 might be more consistent with my read-only length
> recommendation but I'm concern that it requires implementations to use a two
> pass algorithm to ensure atomicity. I'd prefer that not to impose that on
what if you had #1, but the length property, rather than being set to
the new value, gets set to the index of the last undeletable property
+ 1. That's what I would expect to happen.
More information about the Es-discuss