js: accessing scope of parent class

前端 未结 7 571
生来不讨喜
生来不讨喜 2021-01-31 13:45

I have a jquery class within a normal class in javascript. Is it possible to access variables in the scope of the parent class from a callback function in the jquery class?

相关标签:
7条回答
  • 2021-01-31 14:17

    Sorry m8. You have to nest the reference down into the objects like so:

    var simpleClass = function () {
        var _root = this;
        this.status = "pending";
        this.target = jqueryObject;
        this.updateStatus = function() {
            this.root = _root;
            _root.target.fadeOut("fast",function () {
               this.status = "complete"; //this needs to update the parent class 
            });
        };
    };
    

    notice the var _root

    0 讨论(0)
提交回复
热议问题