javascript call 和 apply区别?

来源:luqidong 发布时间:2014-03-13 22:03:12 点击数:
主要的区别在于应用可以让你带参数作为数组调用该函数,调用需要的参数明确地列出。 
看这里和这里。 
伪语法: 
theFunction.apply(valueForThis,arrayOfArgs) 
theFunction.call(valueForThis,ARG1,ARG2,...) 
示例代码: 
function theFunction(name, profession) {
    alert("My name is " + name + " and I am a " + profession + ".");
}
theFunction("John", "fireman");
theFunction.apply(undefined, ["Susan", "school teacher"]);
theFunction.call(undefined, "Claude", "mathematician");