Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将其传递到立即调用的函数表达式中_Javascript_This - Fatal编程技术网

Javascript 将其传递到立即调用的函数表达式中

Javascript 将其传递到立即调用的函数表达式中,javascript,this,Javascript,This,有没有办法将此传递到立即调用的函数表达式中,而不解析为var=this(这在某些情况下不适用) 尝试了以下操作,但没有成功: (function(that) { console.log(that); })(this) 您可能能够为此目的使用或。例如: (function() { console.log(this); // whatever that was specified in the "call" method }).call(this); 您可能能够为此目的使用或。例

有没有办法将
传递到立即调用的函数表达式中,而不解析为
var=this
(这在某些情况下不适用)

尝试了以下操作,但没有成功:

(function(that) {
    console.log(that);
})(this)
您可能能够为此目的使用或。例如:

(function() {
    console.log(this); // whatever that was specified in the "call" method
}).call(this);
您可能能够为此目的使用或。例如:

(function() {
    console.log(this); // whatever that was specified in the "call" method
}).call(this);
代码应该可以工作,确保前面没有没有没有分号的代码

 (function(that) {
        console.log(that);
 })(this) // if here is no semicolon, the next code will be syntax error.
 (function(that) {
        console.log(that);
 })(this);
!function(that) {
    console.log(that);
}(this);
您可以尝试下面的代码,即使在代码省略分号之前也可以

 (function(that) {
        console.log(that);
 })(this) // if here is no semicolon, the next code will be syntax error.
 (function(that) {
        console.log(that);
 })(this);
!function(that) {
    console.log(that);
}(this);
代码应该可以工作,确保前面没有没有没有分号的代码

 (function(that) {
        console.log(that);
 })(this) // if here is no semicolon, the next code will be syntax error.
 (function(that) {
        console.log(that);
 })(this);
!function(that) {
    console.log(that);
}(this);
您可以尝试下面的代码,即使在代码省略分号之前也可以

 (function(that) {
        console.log(that);
 })(this) // if here is no semicolon, the next code will be syntax error.
 (function(that) {
        console.log(that);
 })(this);
!function(that) {
    console.log(that);
}(this);

这在上下文中是什么?您是在对象上还是在函数上下文中调用该函数。。函数.apply(context,arguments)形式可能就是您要查找的..这在上下文中是什么?您是在对象上还是在函数上下文中调用该函数。。function.apply(上下文、参数)表单可能就是您想要的。。