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(上下文、参数)表单可能就是您想要的。。