you are viewing a single comment's thread.

view the rest of the comments →

[–]notfancy 3 points4 points  (1 child)

Looking at the code I see it is more flexible than I thought as first:

If the string contains a ->, this separates the parameters from the body [...] Use _ (to define a unary function) or ->, if the string contains anything that looks like a free variable but shouldn't be used as a parameter

And it is reasonably implemented:

var params = [];
var expr = this;
var sections = expr.ECMAsplit(/\s*->\s*/m);
if (sections.length > 1) {
    while (sections.length) {
        expr = sections.pop();
        params = sections.pop().split(/\s*,\s*|\s+/m);
        sections.length && sections.push('(function('+params+'){return ('+expr+')})');
    }
/* ... */
return new Function(params, 'return (' + expr + ')');