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
Post a Comment