-
Website
http://osteele.com -
Original page
http://osteele.com/archives/2007/07/functional-javascript -
Subscribe
All Comments -
Community
-
Top Commenters
-
llimllib
1 comment · 2 points
-
ultrasaurus
1 comment · 1 points
-
Facebook User
2 comments · 1 points
-
sbecker
1 comment · 1 points
-
mattherdy
1 comment · 1 points
-
-
Popular Threads
Instead of this:
map('x*x', [1,2,3,4])
Why not this:
[1,2,3,4].map('x*x')
Regarding speed, you can improve performance by giving up your favourite idiom:
var args = [].slice.call(arguments, 0);
This is expensive because it creates a new Array object every time you slice an arguments object. Which is very often.
Mozilla provides a static slice method on the Array object. Or you can fake it yourself:
if (!Array.slice) { // Mozilla already supports this
Array.slice = function(array) {
// Slice an array-like object.
var slice = Array.prototype.slice;
return slice.apply(array, slice.call(arguments, 1));
};
}
And use it like this:
var args0 = Array.slice(arguments); // cast to Array
var args1 = Array.slice(arguments, 1); // a normal slice
I use it so often I make it global.
var slice = Array.slice;
var args = slice(arguments);
Hope that helps. Back to reading your source code for me. :)
JavaScript code in functional looks very elegant and readable
"map(guard('10+', not('%2')), [1,2,3,4])" in your Function-level programming section should probably produce
"-> [1,12,3,14]", or shouldn't it?!
I wrote the code that splices the output values into the "examples page":http://osteele.com/sources/javascript/functional exactly because I knew I wouldn't successfully keep them up to date with the expressions, but I couldn't (or didn't take the time to) do the same thing on this blog page :-(