Array.of
# Claude Pache (11 years ago)
Here is one case where literal array syntax is not possible:
class ImprovedArray extends Array { ... }
let a = ImprovedArray.of( ... )
# Rick Waldron (11 years ago)
Back when Dave Herman and I first dreamed up Array.of, I wrote this up: gist.github.com/rwaldron/1074126#arrayof--variable-arity-
# Brendan Eich (11 years ago)
Thanks for the pointer!
I like Claude's use-case and recall Allen citing it too. So, two reasons:
-
Higher-order functional programming wants a function, not literal syntax.
-
Subclassing Array works too, thanks to ES6's class-side inheritance.
What is an example of a use case where one would choose to use Array.of instead of the literal array syntax?