Re:Underscore.js: Annotated Source Code
by jashkenas on Thursday October 07, 2010 @04:00PM
(#1769265)
Full disclosure: I'm the author.
Depending on your definition, nothing in JavaScript is "fully functional programming", because then it would have to be side-effect-free, and JavaScript is very much not that language.
Calling them "functional helpers" is mostly a way of distinguishing the style in which you use them, as opposed to the object-oriented versions of the same helper functions, which can be found in libraries like Prototype.js. The idea here being that you can use them in a functional style without having to extend native objects.
As I mentioned above, calling "map" with the iterator as the final argument isn't a limitation here -- it's a feature. There aren't many (any) situations I've ever seen in real-world JS where you'd want to curry together a list of iterators, and then map them together across the array, all at once. And if you do want to do such a thing, you can accomplish it either like this:
Depending on your definition, nothing in JavaScript is "fully functional programming", because then it would have to be side-effect-free, and JavaScript is very much not that language.
Calling them "functional helpers" is mostly a way of distinguishing the style in which you use them, as opposed to the object-oriented versions of the same helper functions, which can be found in libraries like Prototype.js. The idea here being that you can use them in a functional style without having to extend native objects.
As I mentioned above, calling "map" with the iterator as the final argument isn't a limitation here -- it's a feature. There aren't many (any) situations I've ever seen in real-world JS where you'd want to curry together a list of iterators, and then map them together across the array, all at once. And if you do want to do such a thing, you can accomplish it either like this:
Or, if you want to get fancy, take a look at "compose":http://documentcloud.github.com/underscore/#compose