Skip to content

Instantly share code, notes, and snippets.

@Dremora
Created December 10, 2014 14:47
Show Gist options
  • Save Dremora/9fdb76b5d3c3b9fba54f to your computer and use it in GitHub Desktop.
Save Dremora/9fdb76b5d3c3b9fba54f to your computer and use it in GitHub Desktop.
Binding functions to the 2nd argument
var numbers = ['10', '10', '10', '10'];
numbers.map(parseInt);
// [10, NaN, 2, 3]
var bind2nd = function (fn, val) {
return function () {
var newArgs = [arguments[0], val].concat(Array.prototype.slice.call(arguments, 1))
return fn.apply(null, newArgs);
}
};
var parseDecimalInt = bind2nd(parseInt, 10);
numbers.map(parseDecimalInt);
// [10, 10, 10, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment