What’s the shortest way to define a function in JavaScript?
14:30 07 Aug 2010

What's the shortest way (characters) of creating a "new function" alias.

Basically this is for code golf and minifying code beyond reason. So when you usually would write:

a=function(a,b,c){return a+b+c;}

You could write something like (also let's abstract return keyword as well with global variable R):

a=$("a,b,c","R=a+b+c")
a=$(a,b,c){R=a+b+c}

(Not sure if the second one is possible.)

For the first example the best I've come up with is:

$=function(a,b){return new Function(a,"R=0;"+b+";return R")}

Both the sizes (usage, declaration) matter but usage size is more important.

javascript function alias