javascript - js: accessing scope of parent class -


i have jquery class within normal class in javascript. possible access variables in scope of parent class callback function in jquery class?

a simple example of mean shown below

var simpleclass = function () {         this.status = "pending";     this.target = jqueryobject;     this.updatestatus = function() {         this.target.fadeout("fast",function () {            this.status = "complete"; //this needs update parent class          });     }; }; 

now in above example, callback function tries access scope of jquery object. there way access status variable in parent class?

you set "this" variable in parent function , use in inner function.

var simpleclass = function () {              this.status = "pending";          this.target = jqueryobject;           var parent = this;      this.updatestatus = function() {                      this.jqueryobject.fadeout("fast",function () {                             parent.status = "complete"; //this needs update parent class                       });              };      };  

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) -