js: accessing scope of parent class

前端 未结 7 575
生来不讨喜
生来不讨喜 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:10

    try this:

       var sc = (function(scc){
    
        scc = {};
    
        scc.target = jQueryObject;
    
    
        scc.stt = "stt init";
    
        scc.updateStatus = function(){
            var elem = this;
    
            this.target.click(function(){
                elem.stt= "stt change";
                console.log(elem.stt);
            })
    
        }
    
        return scc;
    
    
    }(sc || {}));
    

    you can also define your target object as private variable

提交回复
热议问题