How can I bind to the right of the function? Example:
var square = Math.pow.bindRight(2);
console.log(square(3)); //desired output: 9
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re looking for partial functions, which are convenient shorthands for aliases.
The “classic” way to do what you’re asking for is with:
Using partial functions it would be:
Unfortunately,
Function.prototype.partialisn’t provided in any browser.Fortunately for you, I’ve been working on a library of what I consider to be essential JavaScript object oriented functions, methods, classes, etc. This is
Function.prototype.partial.js: