I know this is possible with basic closures, but I want to see how to do it with .bind () to better understand this function method. See this sample code:
function add (a, b) {
return a + b;
}
var addTwo = multiply.bind(this, 2);
addTwo(10);
This is working fine. However, is it possible to use .bind () to do the same, but set the second parameter to a fixed value, leaving the first parameter untouched?
I tried to do the following:
function add (a, b) {
return a + b;
}
var addThree = multiply.bind(this, null, 3);
addThree(10);
Is there a way to pick and choose which options to set and leave with .bind ()?
source
share