Depends which parts of functional programming you mean. I use $.each (JQuery), closures, let-bindings, and anonymous functions all the time. Not so much on the statelessness, because:
a.) JavaScript makes it a bit of a pain to deep-copy objects; you can rig up something with $.extend and $.map, but it's not in the standard language the way Python's .copy() and [:] are
b.) Most of the time when you're doing JavaScript, the point is to change the state of the UI. Hard to write stateless code where the intended effect is to change state...
(function(var1, var2) {
// var1 and var2 are now bound within this block
})(val1, val2);
Why use this instead of...
var var1 = val1;
var var2 = val2;
// do stuff with var1 & var2
It's because if you have any closures within the block, they'll capture the bindings of var1 and var2 instead of their values. That means that if you're inside a loop, your bindings will be overwritten each time through, so you could end up creating a dozen closures that all do the same thing.
Here's an example from a JQuery patch I did a couple weeks ago:
Before it used an eval statement to directly write the value into the source code of the closure. After, it captures the value with a let-binding and then returns a closure over the current value instead of the current binding.
Thanks. I thought that someone was suggesting that they were using let = ... syntax. Now, I understand that the idiom you showed is "let binding" in the Javascript world.
a.) JavaScript makes it a bit of a pain to deep-copy objects; you can rig up something with $.extend and $.map, but it's not in the standard language the way Python's .copy() and [:] are
b.) Most of the time when you're doing JavaScript, the point is to change the state of the UI. Hard to write stateless code where the intended effect is to change state...