Call JavaScript's setTimeOut in dojo Class -


i'm trying convert javascript functions dojo class. i've settimeout("functionname",2000) in 1 of js method. how call method in class decared using dojo.declare method. example, below custom class.

    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 call "isstatechanged" method after 2000 ms. how do this?                         settimeout("isstatechanged",2000);                     },                                       isstatechanged:function(){                         alert('state updated');                     }                 }); var person=new person(12,"us","test","teststate"); person.movetonewstate("newstate"); 

please let me know how can call isstatechanged method movetonewstate method after 2000ms.

what you're looking way of binding this value function settimeout call:

movetonewstate:function(newstate){     // remember `this` in variable within function call     var context = this;      // misc logic     this.state = newstate;      // set callback     settimeout(function() {         // call         context.isstatechanged();     }, 2000); },      

the above using closure bind context (see: closures not complicated), usual way this. dojo may offer built-in function generating these "bound" callbacks (prototype , jquery do). (edit: does, in comment below peller kindly pointed out dojo.hitch.)

more general concept here: you must remember this


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -