3 ms·
The best reason to have new-less constructors is because it's now possible to use them as higher-order functions. [1,2,3].map(User)
by zimbatm 12y ago
The best reason to have new-less constructors is because it's now possible to use them as higher-order functions.
[1,2,3].map(User)
- drinchev 12y agoOr the alternative : [1,2,3].map( function(i) { return new User(i); } ); might seem more reasonable in the JS world.
- agumonkey 12y agoIt's a valuable but unnecessary intermediate step if you go into functional idioms (map, fold, closures) fully. raganwald books cover this way of using javascript https://leanpub.com/u/raganwald https://leanpub.com/u/raganwald
- insin 12y agoAs long as the constructor doesn't take multiple arguments [1], otherwise: [1, 2, 3].map(id => User(id)) [1] http://speakingjs.com/es5/ch15.html#_pitfall_unexpected_optional_parameters http://speakingjs.com/es5/ch15.html#_pitfall_unexpected_opti...