var tempFn = function(someText){
console.log(someText);
}
tempFn('siva');
// where I simply call the function with text 'siva'
VS
tempFn.call(this,'siva');
// where I call the function using call method
这些方法有什么区别?
答案 0 :(得分:3)
当您使用call
表单时,您明确了将调用该函数的上下文。
上下文将确定函数执行时this
的值是什么。
在你的情况下,你传递this
无论如何都是默认的,所以这是一个无操作。此外,您的tempFn
函数不会调用this
关键字,因此如果您传入不同的范围,无论如何都无关紧要。