Created
December 10, 2014 14:47
-
-
Save Dremora/9fdb76b5d3c3b9fba54f to your computer and use it in GitHub Desktop.
Binding functions to the 2nd argument
This file contains hidden or 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
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