You are looking for partial functions that are convenient abbreviations for aliases.
The "classic" way of doing what you ask for is:
var square = function (x) { return Math.pow(x, 2); };
Using partial functions, this will be:
var square = Math.pow.partial(undefined, 2); console.log(square(3));
Unfortunately, Function.prototype.partial
not provided in any browser.
Luckily for you, I worked on a library of what I consider to be essential object-oriented JavaScript functions, methods, classes, etc. This is Function.prototype.partial.js
:
(function () { "use strict"; if (!Function.prototype.partial) { Function.prototype.partial = function () { var fn, argmts; fn = this; argmts = arguments; return function () { var arg, i, args; args = Array.prototype.slice.call(argmts); for (i = arg = 0; i < args.length && arg < arguments.length; i++) { if (typeof args[i] === 'undefined') { args[i] = arguments[arg++]; } } return fn.apply(this, args); }; }; } }());
source share