one would choose to use
Array.of instead of the literal array syntax?
Back when Dave Herman and I first dreamed up Array.of, I wrote this
up: https://gist.github.com/rwaldron/1074126#arrayof--variable-arity-
Rick
Here is one case where literal array syntax is not possible
What is an example of a use case where one would choose to use Array.of
instead of the literal array syntax?
--
R. Mark Volkmann
Object Computing, Inc.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Le 3 mars 2014 à 04:22, Mark Volkmann r.mark.volkm...@gmail.com a écrit :
What is an example of a use case where one would choose to use Array.of
instead of the literal array syntax?
Here is one case where literal array syntax is not possible:
class ImprovedArray extends Array
This is an old thread which I like to mention again. The proposal is change
the method name from Array.of() to Array.fromElements() to make it clear
especially for non-English native programmers.
It seems the thread is totally ignored...
On Tue, Aug 28, 2012 at 5:56 PM, Jussi Kalliokoski
From: Shijun He hax@gmail.com
Subject: Re: About Array.of()
This is an old thread which I like to mention again. The proposal is
change the method name from Array.of() to Array.fromElements() to make it
clear especially for non-English native programmers.
`Array.of` sounds a lot more
Array.of sounds expressive only for native speakers.
English is not my first language and it sounded expressive to me. I've
asked 5 random friends that code and they all said it sounded fine to them.
While that's not real evidence, it still shows that the only doesn't hold
here.
The only valid
On Dec 18, 2013, at 11:01 AM, Shijun He wrote:
...
2)
In fact such expressive is MEANINGLESS because we will never write `var a =
Array.of(1, 2, 3)` instead of `var a = [1, 2, 3]`
Note that 'of' works to create instances of subclasses or Array (and typed
arrays) while array literals
On Thu, Dec 19, 2013 at 4:04 AM, Benjamin (Inglor) Gruenbaum
ing...@gmail.com wrote:
Array.of sounds expressive only for native speakers.
English is not my first language and it sounded expressive to me. I've
asked 5 random friends that code and they all said it sounded fine to them.
While
On Thu, Dec 19, 2013 at 4:37 AM, Allen Wirfs-Brock al...@wirfs-brock.comwrote:
On Dec 18, 2013, at 11:01 AM, Shijun He wrote:
...
2)
In fact such expressive is MEANINGLESS because we will never write `var
a = Array.of(1, 2, 3)` instead of `var a = [1, 2, 3]`
Note that 'of' works
Array.from(arguments) }
Remarkably, `Array.fromElements` sounds particularly bad to my ears, because it
seems to be a synonym of `Array.from` when applied to an array. (Array from
[the] elements [of] ...)
Personally, I'd not thought that `Array.of` would be a problem, but apparently,
since even people
My first post to this mailing list, so hi everyone!
I agree with Domenic, Array.fromElements would be a good name (though I
have no problem with Array.of). Just don't go with Array.new (I agree with
Rick here, it should match the constructor - Array should be no exception,
broken constructor
On Aug 26, 2012, at 4:30 PM, Brendan Eich bren...@mozilla.com wrote:
Rick Waldron wrote:
But Array.of is not. Maybe Array.new is a good name.
Array.of is unambiguous with the current ES specification
Array.new is ok too, though -- no problem with a reserved identifier as a
property name
On Tue, Aug 28, 2012 at 9:59 AM, Maciej Stachowiak m...@apple.com wrote:
On Aug 26, 2012, at 4:30 PM, Brendan Eich bren...@mozilla.com wrote:
Rick Waldron wrote:
But Array.of is not. Maybe Array.new is a good name.
Array.of is unambiguous with the current ES specification
Array.new
However, I'm still not quite sure what the use case is for this. For code
generation, if you know how many elements there are and what they are enough
to put them in the Array.of(...,...,...) call, why not just use
[...,...,...]? Unless it's supposed to be used for converting array-likes
On Tue, Aug 28, 2012 at 12:40 PM, Axel Rauschmayer a...@rauschma.de wrote:
However, I'm still not quite sure what the use case is for this. For code
generation, if you know how many elements there are and what they are
enough to put them in the Array.of(...,...,...) call, why not just use
I don't think that screenshots of search suggestions for a language feature
that hasn't even been published is valid argument in this discussion.
I'd also argue that these results support the current Array.of definition,
eg.
I need to make an array of strings:
Array.of( A, B, C, D );
...Which
Robb wrote:
I agree with Rick on the general feeling with Array.of
If arguing ambiguity I would argue a better method name for type
guarded arrays would be Array.ofType
On Sun, Aug 26, 2012 at 8:56 PM, Rick Waldron waldron.r...@gmail.com
mailto:waldron.r...@gmail.com wrote:
On Sunday
Isn't there a name that we already use for alternative constructors: create?
let object = Object.create(null);
let array = Array.create(A, B, C);
Kevin
___
es-discuss mailing list
es-discuss@mozilla.org
, with the wrong defaults
for writable configurable and arguably enumerable.
The Ruby precedent for Array.new appeals to me (and I'm not a Rubyist).
I could live with Array.of but even ignoring search-engine usability,
using a preposition for a constructor name, rather than a verb or a
verb'ed
, which takes a pdmap as
second parameter. That is a complicated beast, with the wrong defaults
for writable configurable and arguably enumerable.
The Ruby precedent for Array.new appeals to me (and I'm not a Rubyist).
I could live with Array.of but even ignoring search-engine usability
On Tue, Aug 28, 2012 at 1:55 AM, Rick Waldron waldron.r...@gmail.com wrote:
I don't think that screenshots of search suggestions for a language feature
that hasn't even been published is valid argument in this discussion.
I'd also argue that these results support the current Array.of
agree you 'new' should match constructor, except Array. Array
constructor is broken (that's why we need Array.of/new/create
whatever) and NO ONE really use Array constructor at all (programmers
are educated to use literal initializer instead).
--
hax
do I wish to
I agree you 'new' should match constructor, except Array. Array
constructor is broken (that's why we need Array.of/new/create
whatever) and NO ONE really use Array constructor at all (programmers
are educated to use literal initializer instead).
Too true.
Rick, it's important
as its operator
equivalent (for all constructors, not just Array). By no means do I wish
to
I agree you 'new' should match constructor, except Array. Array
constructor is broken (that's why we need Array.of/new/create
whatever) and NO ONE really use Array constructor at all (programmers
;)
On Mon, Aug 27, 2012 at 10:55 AM, Matthew Robb matthewwr...@gmail.com wrote:
I agree with Rick on the general feeling with Array.of
If arguing ambiguity I would argue a better method name for type guarded
arrays would be Array.ofType
On Sun, Aug 26, 2012 at 8:56 PM, Rick Waldron waldron.r
;)
On Mon, Aug 27, 2012 at 10:55 AM, Matthew Robb matthewwr...@gmail.com wrote:
I agree with Rick on the general feeling with Array.of
If arguing ambiguity I would argue a better method name for type guarded
arrays would be Array.ofType
On Sun, Aug 26, 2012 at 8:56 PM, Rick Waldron waldron.r
:
I agree with Rick on the general feeling with Array.of
If arguing ambiguity I would argue a better method name for type guarded
arrays would be Array.ofType
On Sun, Aug 26, 2012 at 8:56 PM, Rick Waldron waldron.r...@gmail.com
wrote:
On Sunday, August 26, 2012 at 7:30 PM, Brendan Eich
Hi,
I don't think Array.of() is useful, just stick on array literal seems enough:
var a = [1,2,3]
var a1 = [3]
Why we need this:
var a = Array.of(1,2,3)
var a1 = Array.of(3)
Is there any special benefit I missed?
And there is another reason why I don't like Array.of() , myself write
a small
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
Rick Waldron wrote:
If you replace that by using Array.of(), you avoid this gotcha
That's right -- Array.of is an alternative constructor to use in
preference to Array, on account of Array's heinous special-case for the
one-numeric-argument case
, ...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
Rick Waldron wrote:
But Array.of is not. Maybe Array.new is a good name.
Array.of is unambiguous with the current ES specification
Array.new is ok too, though -- no problem with a reserved identifier as
a property name. It's darn nice for Rubyists.
OTOH Array.of matches the preposition
On Sunday, August 26, 2012 at 7:30 PM, Brendan Eich wrote:
Rick Waldron wrote:
But Array.of is not. Maybe Array.new is a good name.
Array.of is unambiguous with the current ES specification
Array.new is ok too, though -- no problem with a reserved identifier as
a property
I agree with Rick on the general feeling with Array.of
If arguing ambiguity I would argue a better method name for type guarded
arrays would be Array.ofType
On Sun, Aug 26, 2012 at 8:56 PM, Rick Waldron waldron.r...@gmail.comwrote:
On Sunday, August 26, 2012 at 7:30 PM, Brendan Eich wrote
of array of in non-english languages seems most come from the
programmers' input, so it shows how worldwide programmers think what
array of means ;)
On Mon, Aug 27, 2012 at 10:55 AM, Matthew Robb matthewwr...@gmail.com
wrote:
I agree with Rick on the general feeling with Array.of
If arguing
Alex I think whatever method we have natively won't be enough for this or
that case, plus once a method is implemented native his signature becomes
legacy developers may like or not.
With Object.defineProperty we *could* pollute Array.prototype avoiding the
most annoying and idiotic thing
glad somebody said that!
Also I would pollute performance oriented methods rather than whatever
framework sugar anybody could easily add where unique() and remove(all) may
be part of these cases while fill() could be superfluous.
Andrea
On Mon, Jul 11, 2011 at 6:01 PM, Allen Wirfs-Brock
On Jul 26, 2011, at 7:10 AM, Andrea Giammarchi wrote:
glad somebody said that!
Also I would pollute performance oriented methods rather than whatever
framework sugar anybody could easily add where unique() and remove(all) may
be part of these cases while fill() could be superfluous.
I feel
On Jul 10, 2011, at 12:09 PM, Dmitry A. Soshnikov wrote:
And by the way, an efficient `Array.prototype.unique` also would be nice to
have, since in JS in general it's hard to implement it's efficiently (in
lower level at least it will iterate faster).
[1, 3, 2, 5, 5, 3].unique(); // [1,
On 11.07.2011 20:01, Allen Wirfs-Brock wrote:
On Jul 10, 2011, at 12:09 PM, Dmitry A. Soshnikov wrote:
And by the way, an efficient `Array.prototype.unique` also would be nice to
have, since in JS in general it's hard to implement it's efficiently (in lower
level at least it will iterate
Array.from is a good addition, I guess any good framework has it.
Though, `Array.of` in contrast doesn't bring much of a sugar. Compare
these two apples-to-apples:
Array.of( things, that, aren't, currently, an, array )
vs.
[things, that, aren't, currently, an, array]
what's the goal
On 10.07.2011 14:27, Mike Shaver wrote:
On Sun, Jul 10, 2011 at 6:06 AM, Dmitry A. Soshnikov
dmitry.soshni...@gmail.com wrote:
The problem:
Array(4).map(function(x) x * x); // [NaN, NaN, NaN, NaN]
I think it actually produces just [ , , , , ], because map skips
holes. (If you see the NaN
On Sun, Jul 10, 2011 at 7:09 AM, Dmitry A. Soshnikov
dmitry.soshni...@gmail.com wrote:
If I hadn't made map skip holes, then the fill pattern would be simple
enough:
Array(4).map(function (_,x) x * x);
It's in particular case, you try to multiply indices, which in current
implementation of
On 10.07.2011 15:14, Mike Shaver wrote:
On Sun, Jul 10, 2011 at 7:09 AM, Dmitry A. Soshnikov
dmitry.soshni...@gmail.com wrote:
If I hadn't made map skip holes, then the fill pattern would be simple
enough:
Array(4).map(function (_,x) x * x);
It's in particular case, you try to multiply
Le 10/07/2011 12:06, Dmitry A. Soshnikov a écrit :
(...)
Another thing to consider is `Array.prototype.fill` method which we
discussed before.
The problem:
Array(4).map(function(x) x * x); // [NaN, NaN, NaN, NaN]
(by the way, this mistaken example is still mentioned in this document
On Jul 10, 2011, at 3:06 AM, Dmitry A. Soshnikov wrote:
Array.from is a good addition, I guess any good framework has it.
Though, `Array.of` in contrast doesn't bring much of a sugar. Compare these
two apples-to-apples:
Array.of( things, that, aren't, currently, an, array )
vs
On 10.07.2011 20:36, Brendan Eich wrote:
On Jul 10, 2011, at 3:06 AM, Dmitry A. Soshnikov wrote:
Array.from is a good addition, I guess any good framework has it.
Though, `Array.of` in contrast doesn't bring much of a sugar. Compare these two
apples-to-apples:
Array.of( things, that, aren't
On Jul 10, 2011, at 9:59 AM, Dmitry A. Soshnikov wrote:
On 10.07.2011 20:36, Brendan Eich wrote:
So the goal of Array.of is to provide a constructor that, unlike Array, does
not have that insane special case for Array(42), which presets length (and
hints to implementations to preallocate
A. Soshnikov
lt;dmitry.soshni...@gmail.comgt; wrote:
On 10.07.2011 20:36, Brendan Eich wrote:
gt; On Jul 10, 2011, at 3:06 AM, Dmitry A. Soshnikov wrote:
gt;
gt;gt; Array.from is a good addition, I guess any good framework has it.
gt;gt;
gt;gt; Though, `Array.of` in contrast doesn't bring much
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really exciting use
cases where Array.of would outshine anything that already exists. I say
strike it from the wishlist.
Higher-order programming with Array as constructing-function
On 10.07.2011 21:18, Brendan Eich wrote:
On Jul 10, 2011, at 9:59 AM, Dmitry A. Soshnikov wrote:
On 10.07.2011 20:36, Brendan Eich wrote:
So the goal of Array.of is to provide a constructor that, unlike Array, does
not have that insane special case for Array(42), which presets length
On 10.07.2011 21:32, Allen Wirfs-Brock wrote:
On Jul 10, 2011, at 10:23 AM, Brendan Eich wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really
exciting use cases where Array.of http://Array.of/ would outshine
anything
On Jul 10, 2011, at 10:32 AM, Allen Wirfs-Brock wrote:
On Jul 10, 2011, at 10:23 AM, Brendan Eich wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really exciting
use cases where Array.of would outshine anything
On Jul 10, 2011 1:23 PM, Brendan Eich bren...@mozilla.com wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really
exciting use cases where Array.of http://Array.of/ would outshine
anything that already exists. I say
On Jul 10, 2011, at 10:32 AM, Allen Wirfs-Brock wrote:
Yes, if you actually need to pass Array.of as a function argument. Of course
if we have block lambdas you could just say:
hof({|a|[a]})
instead of
hof(Array.of)
actually the above aren't equivalent. The block lambda
I dig Array.from, and have manually made sugar for that in my projects.
Array.of is something I have also wanted though I had been struggling
with a name for it.
Until now if I wanted to avoid setting the array length I would do
something like ns.Array.from([23]), but Array.of is nice too
On 10.07.2011 22:26, John-David Dalton wrote:
I dig Array.from, and have manually made sugar for that in my projects.
Array.of is something I have also wanted though I had been struggling
with a name for it.
It's interesting -- can you show where and how?
Until now if I wanted to avoid
On Jul 10, 2011, at 10:40 AM, Dmitry A. Soshnikov wrote:
On 10.07.2011 21:23, Brendan Eich wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really exciting
use cases where Array.of would outshine anything that already
On 10.07.2011 22:44, Brendan Eich wrote:
On Jul 10, 2011, at 10:40 AM, Dmitry A. Soshnikov wrote:
On 10.07.2011 21:23, Brendan Eich wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really
exciting use cases where Array.of
wrote:
On 10.07.2011 22:44, Brendan Eich wrote:
On Jul 10, 2011, at 10:40 AM, Dmitry A. Soshnikov wrote:
On 10.07.2011 21:23, Brendan Eich wrote:
On Jul 10, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any really
exciting use cases where Array.of
with any really
exciting use cases where Array.of http://Array.of/ would
outshine anything that already exists. I say strike it from the
wishlist.
Higher-order programming with Array as constructing-function bites
back for the single-number-argument case. That's where Array.of helps.
You mean
, 2011, at 10:18 AM, Rick Waldron wrote:
The more I think about it, I still can't come up with any
really exciting use cases where Array.of
http://Array.of/ would outshine anything that already exists.
I say strike it from the wishlist.
Higher-order programming with Array
I mentioned two benefits I can see to Array.of over []-literals here:
https://twitter.com/#!/littlecalculist/status/89854372405723136
1) With Array.of you know you aren't going to accidentally create holes, and
2) if you're passing it to a higher-order function you know you aren't going
can't come up with any really exciting
use cases where Array.of would outshine anything that already exists. I
say strike it from the wishlist.
Higher-order programming with Array as constructing-function bites back
for the single-number-argument case. That's where Array.of helps.
You
:
The more I think about it, I still can't come up with any really
exciting use cases where Array.of http://Array.of/ would
outshine anything that already exists. I say strike it from the
wishlist.
Higher-order programming with Array as constructing-function bites
back for the single-number
65 matches
Mail list logo