JavaScript/jQuery variable scope in class (this)

后端 未结 2 1696
时光说笑
时光说笑 2021-01-24 11:59

I\'m writing simple slider for my website. This slider contains list items. I want to use OOP approach.

My actual code:

var miniSlider = function(objId)
         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-24 12:13

    Save a reference to this in a local variable, and use that variable instead of this in the nested function.

    var self = this;
    this.pagerNext.on("click", function() {
      alert(self.obj.settings['items']);
    });
    

提交回复
热议问题