Skip to content

Instantly share code, notes, and snippets.

@Williammer
Last active June 18, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Williammer/8869994c363f0480a37691e14e206032 to your computer and use it in GitHub Desktop.
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.
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