Without worrying about preprocessors or compilers, you can do the following, which shortens the callback syntax. One thing is that the scope of "this" is not considered ... but for your use case, I don't think it matters:
var ok = function(a,b) { return (a==b); }; var f = function(func) { var args = Array.prototype.slice.call(arguments, 1); return function() { return func.apply(undefined,args); }; }; var callback = f(ok,10,10); console.log(callback());
source share