Using apply() vs call(), which one to use in this case?
This question already has an answer here:
Apply takes a single array of arguments, useful for method chaining, the javascript equivalent of calling super. in Java etc.
function makeNoise() {
Foo.prototype.makeNoise.apply(this, arguments);
}
Call takes list of parameters, more useful other situations where the arguments are only available as single variables.
fn.call(this, x, y, z);
which would just be shorthand for
fn.apply(this, [x, y, z])
Given you have an array of arguments you need to use apply()
链接地址: http://www.djcxy.com/p/18042.html