Rick Waldron (2012-08-26T11:14:09.000Z)
domenic at domenicdenicola.com (2014-01-03T16:25:00.926Z)
Thanks for the feedback, allow me to explain the rationale for `Array.of`: One of the main goals of ES6 is to become a better language for library writers and code generators. For compilation targets, ES/JS can't assume that implementations will always know what its factories are expected to construct: Imagine the following piece of code is used in a VM (think Dart->JS, LLJS->JS) ```js var o = (function( construct, ...rest ) { return new construct( rest ); })( factory [, variable arity args] ); ``` If factory is `Array` and only one numeric arg is given, inline like this: ```js var o = (function( construct, ...rest ) { return new construct( rest ); })( Array, 10 ); ``` The result of `o` will be an array with 10 empty indexes, as if it were called like: ```js new Array(10) ``` If you replace that by using `Array.of()`, you avoid this "gotcha" More comments inline... On Sunday, August 26, 2012 at 5:53 AM, Shijun He wrote: > Is there any special benefit I missed? Explained above :) > And there is another reason why I don't like Array.of() , myself write > a small library which use Array.of(type) to get a "strong-typed" > array: I'd argue that if code is extending ES built-ins with non-standard properties, it accepts the risk that one day it may be in conflict.