Javascript outer scope variable access

后端 未结 1 631
栀梦
栀梦 2021-01-12 03:07
OperationSelector = function(selectElement) {
    this.selectElement = selectElement;
}

OperationSelector.prototype.populateSelectWithData = function(xmlData) {
            


        
1条回答
  •  不要未来只要你来
    2021-01-12 03:40

    Assign it to a local variable in the function scope before your iteration function. Then you can reference it within:

    OperationSelector = function(selectElement) { 
        this.selectElement = selectElement; 
    } 
    
    OperationSelector.prototype.populateSelectWithData = function(xmlData) { 
        var os = this;
        $(xmlData).find('operation').each(function() { 
            var operation = $(this); 
            os.selectElement.append(new Option(operation.attr("title")));
        }); 
    }
    

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