作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一些 JS 代码如下:
var x = self.someAJAXResponseJSON; // x has some object value here.
setTimeout(function(x){
console.log("In setTimeout:", x); // But x is undefined here
}, 1000);
所以我想将x
传递给setTimeout
回调函数。但是我在 setTimeout
中得到的 x
是未定义的。
我做错了什么?
知道如何使用 Dojo.js 解决类似问题吗?
setTimeout(dojo.hitch(this, function(){
this.executeSomeFunction(x); // What should this be?
console.log("In setTimeout:", x); // But x is undefined here
}), 1000);
最佳答案
或者,您可以在不创建闭包的情况下执行此操作。
function myFunction(str1, str2) {
alert(str1); //hello
alert(str2); //world
}
window.setTimeout(myFunction, 10, 'hello', 'world');
但请注意它不适用于 IE < 10
according to MDN .
关于javascript - 当作为参数传递给 setTimeout 回调函数时,全局变量被记录为未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326721/
我正在使用 Jackson 序列化实现 Map 的自定义类。但在幕后,它实际上是一个 Map (此类代表 HTTP 请求参数),我希望 Jackson 将其序列化,就好像它是 Map 一样。 。我原以
这个问题在这里已经有了答案: Where and why do I have to put the "template" and "typename" keywords? (8 个答案) 关闭 8
我最近遇到了一些渐近符号,当这个问题出现时,它是 50 n logn 并且根据流行的规则获得 Big-OH 符号是简单地删除常数和低阶项。但是 50n logn 也是n^5 的 BIG-OH。那么
我是一名优秀的程序员,十分优秀!