【发布时间】:2011-02-23 14:08:06
【问题描述】:
我正在尝试将我的 JavaScript 函数转换为 dojo 类。我的一个 JS 方法中有一个 setTimeOut("functionName",2000)。如何从使用 dojo.declare 方法声明的类中的方法调用它。例如,下面是我的自定义类。
dojo.declare("Person",null,{
constructor:function(age,country,name,state){
this.age=age;
this.country=country;
this.name=name;
this.state=state;
},
moveToNewState:function(newState){
this.state=newState;
//I need to call "isStateChanged" method after 2000 ms. How do I do this?
setTimeOut("isStateChanged",2000);
},
isStateChanged:function(){
alert('state is updated');
}
});
var person=new Person(12,"US","Test","TestState");
person.moveToNewState("NewState");
请告诉我如何在 2000 毫秒后从 moveToNewState 方法调用 isStateChanged 方法。
【问题讨论】:
-
它是
setTimeout,而不是setTimeOut,最好(总是或几乎总是)将函数引用传递给它,而不是它必须编译的字符串。
标签: javascript dojo settimeout