在javascript中,如果我必须在不同的上下文中调用一个函数,那么调用它的首选方法是什么。为什么?
this
1)作为参数传递,如下所示:
callthisfunction(arg1, arg2, this);
function callthisfunction(arg1, arg2, context) {}
或者
2)使用如下所示的调用/应用:
callthisfunction.call(this, arg1, arg2);
在javascript中,如果我必须在不同的上下文中调用一个函数,那么调用它的首选方法是什么。为什么?
this
1)作为参数传递,如下所示:
callthisfunction(arg1, arg2, this);
function callthisfunction(arg1, arg2, context) {}
或者
2)使用如下所示的调用/应用:
callthisfunction.call(this, arg1, arg2);