domenic at domenicdenicola.com (2014-01-03T16:26:09.146Z)
On Sun, Aug 26, 2012 at 7:14 PM, Rick Waldron <waldron.rick at gmail.com> wrote: > If you replace that by using Array.of(), you avoid this "gotcha" So you still need some code like: ```js if (constructor === Array) return Array.of(rest) else return new construct(rest) ``` And of cause we can write it as: ```js if (constructor === Array) return [rest] ``` Or, maybe you mean we should write ```js o = ....(Array.of, 10) instead of o = ....(Array, 10) ``` But is this case strong enough to add such a simple function to standard library? > 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. And if it should be added, could you choose a better name? `Array.isArray` is good example which will not introduce any ambiguity. But `Array.of` is not. Maybe `Array.new` is a good name.
On Sun, Aug 26, 2012 at 7:14 PM, Rick Waldron <waldron.rick at gmail.com> wrote: > 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: > > 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: > > new Array(10) > > If you replace that by using Array.of(), you avoid this "gotcha" > So you still need some code like: if (constructor === Array) return Array.of(rest) else return new construct(rest) And of cause we can write it as: if (constructor === Array) return [rest] Or, maybe you mean we should write o = ....(Array.of, 10) instead of o = ....(Array, 10) But is this case strong enough to add such a simple function to standard library? > 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. And if it should be added, could you choose a better name? Array.isArray is good example which will not introduce any ambiguity. But Array.of is not. Maybe Array.new is a good name. Thank you! -- hax