herby at mailbox.sk
Mon Jun 15 17:38:46 UTC 2015
Allen Wirfs-Brock wrote:
> On Jun 3, 2015, at 3:46 AM, Leon Arnott wrote:
>> This reminds me: I feel like the spec should've added
>> Array.prototype[Symbol.isConcatSpreadable] (value:true,
>> configurable:false, writable:false), and eliminated the final
>> IsArray() test from
>> Would've made the Array#concat() behaviour a little cleaner, in my
>> Unless, perhaps, the point was to leave it open and allow the end-user
>> to monkey-patch it to false, thus finally "fixing" Array#concat()
>> after all these years...? Was that the plan?
> Exactly! ES6 has to preserve the previous semantics for all existing programs, including programs that attempted to create Array subclasses in various ad hoc manners.
> @@isConcatSpreadable exists to allow new ES6-level array subclasses to explicitly opt-out of the legacy implicit spread behavior of concat.
So when one actually _wants_ to concat (as, add elements of the
iterable), it should stop using concat for that and must do something like
var concatenated = first.slice();
concatenated.push(...second, ...third, ...fourth);
More information about the es-discuss