【发布时间】:2014-09-11 08:42:59
【问题描述】:
我无法将值传递给作为 setTimeout 函数的参数传递的匿名函数的参数。
我已经卡了 5 个多小时了……
请看下面的代码,给我一个帮助。
提前致谢!!
if (_que.length > 0){
var nextUrl = _shiftNextUrlFromQue();
//here, the value for nextUrl exists.the value is url string.
console.log(nextUrl);
setTimeout(function(nextUrl) {
//here, the value is undefined.
_analyzeUrl(nextUrl);
}, 10000
);
}
【问题讨论】:
-
我很确定您甚至不需要将其作为参数传递给 setTimeout 中的函数...只需将参数留空即可:)
-
感谢您的帮助!
-
是的,回调的第一个参数是
undefined,它会覆盖该上下文中的变量。 -
那么,你的意思是这样吗? setTimeout(function() { _analyzeUrl(nextUrl); }, 10000 );
-
哇!我懂了。我现在就去试试!
标签: javascript jquery