On 12.05.2010 2:03, Jordan Osete wrote:
What about some simple getItem( index ) / setItem( index, item )
variation ?
More language-like and more convenient than the current solutions,
they could easily be defined with slice- and splice-compatible behaviour:
Array.prototype.getItem = function (i) {return this.slice (i, 1)[0];};
Array.prototype.setItem = function (i, v) {this.splice (index, 1,
[v]);};
That's too bad concurrency for alternative and already invented
syntactic sugar for that -- a bracket notation used in many languages. I
should mention Python again and its very convenient indexing/slicing:
a[-1] # last
a[2:5] # slice
Unfortunately (or fortunately -- it depends), repeat, ES has no semantic
differentiation between dot and bracket notation. And that means the
only way (to keep the common approach for bracket notation as just an
alternative property accessory, but not for subscriptable objects). The
only way to to do this is to overload also [[Get]] (with clarifying
inheritance points of "-3" property from other link of the prototype chain).
And taking into account, that the main objective is backward
compatibilities and decreasing of the new syntax, I'm not sure ES will
do this. Although, it is of course convenient for exactly arrays.
And getItem / setItem in my opinion looks too "desugared" in era when
many languages have the convenient sugar for that. Don't forget, that
scripting language should be easy to use with elegant easy to
write/remember and convenient constructions. From this viewpoint
literary-like Java's style with its long complete "sentences" (long
names) seems even less elegant.
So, don't think that JS -- a highly abstracted language, needs this
getItem / setItems, even if for less abstracted languages (even for
Assembler) there is bracket notation for addressing offset from the base
of a structure.
Dmitry.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss