function commonFunction(x, y) {
return x * y * 2;
}
var ints = [1,2,3];
var result = ints.map(commonFunction);
//result = [0,4,12]
Correct me if i'm wrong, commonFunction
is expecting 2 parameters and by calling commonFunction
inside a Array.map
, first parameter automatically filled up by the each individual of the array.
As shown above, second parameter wasn't provided, why it yields the result of [0,4,12]
?
I understand that in order to achieve the correct result, I can use bind
as below:
var result = ints.map(commonFunction.bind(this,3));
//result = [6,12,18]