Python like lambda - $.lambda
Hello again, everybody.
I wonder if a "python like" lambda function could be interesting for
anybody.
In some piece of my code, I am using them, already, and as you can see
its implementation is really simple, because It does not require more
than 3 lines (in core):
$.extend({
lambda:function(lambda){
var text = lambda.split(":");
return new Function(text.shift(), "return " +
text.join(":"));
}
});
So, it is really easy to maintain, and it could be useful to quickly
delegate some task, such:
["a","b","c"].map($.lambda("v:v.toUpperCase()"))
// A,B,C
or more specific for jQuery, something like:
$("a").click($.lambda(":false"));
Kind Regards
P.S. it should be compatible with Rhino too, even if eval has been
disabled.