How to call a method inside a javascript object

后端 未结 5 577
北荒
北荒 2021-02-08 17:30

I\'m just learning about how to best organize my javascript code, and I had a question regarding this small piece of code I wrote:

var reportsControllerIndex = {         


        
5条回答
  •  名媛妹妹
    2021-02-08 18:13

    You want to store the this binding in a variable.

    drawMap: function() {
        var _this = this;
        $.getJSON('/reports.json', function(data) {
            _this.plotMapPoints(data);         
        });
    }
    

提交回复
热议问题