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 that's not real evidence, it still shows that the "only" doesn't hold > here. > Could you ask what's your and your friend's native language? > > > The only valid use case of Array.of is high-order function. > > No it's not. The main use case I see is converting array like structures > (like NodeLists) to arrays without having to do that dirty > `Array.prototype.splice.call` call: > > Array.of(document.querySelectorAll(".bar")) > Oops, it should be Array.from(document.querySelectorAll('.bar')). > > Higher order functions are a real use case but for sure not the only one. > I completely agree with Rick that fromElements is confusing for the API > __especially__ that creating an array out of actual DOM Elements _is_ a use > case and it implies that it only works for _that_ use case. > I already give some alternatives. Just choose what you like. > > Like I said, the _optimal_ thing would have been to be able to do > `Array(arrayLike)` and have it "just work" and create a new array from that > collection (like collections tend to do in Java, C#, Python etc) but it's > too late for that. That breaks ES (Array([1]) returns [[1]]). Array.of > seems very close of that, you make an array of the items passed. The fact > it's a static method makes it very clear that that's what it does IMO > (although personally I'd favor putting it somewhere else). > > So could I use your misunderstanding of Array.of/from as a example that Array.of is a bad name? :)
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss