Last active
June 18, 2018 10:03
-
-
Save Williammer/8869994c363f0480a37691e14e206032 to your computer and use it in GitHub Desktop.
jsBasic.bindRight.js - implementation for the bind function that accept arguments from right most to the left.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.bindRight = function (context, ...firstArgs) { | |
return (...secArgs) => { | |
return this.apply(null, [...secArgs.reverse(), ...firstArgs.reverse()]); | |
}; | |
}; | |
function add(x, y, z) { | |
return 100 * x + 10 * y + z; | |
} | |
const add2 = add.bindRight(null, 1, 2); | |
const result = add2(3); | |
console.log('--result: ', result); // => 321 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment