How can I access variables outside of current scope in javascript?

后端 未结 3 955
小蘑菇
小蘑菇 2020-12-17 02:02

I\'m writing an application in javascript and cannot figure it out how to access the variables declared in my function, inside this jquery parse. Inside I can access global

3条回答
  •  清酒与你
    2020-12-17 02:43

    I made a working demo (I changed it to use classes so it would work with HTML).

    function CsvReader(simName) {
        this.initFileName = "somepath";
        this.eventsFileName = "somepath";
        var context = this;
        $(simulationFiles).find('simulation').each(function() {
           if ($(this).attr("name") == simName) {
               context.initFileName += $(this).find("init").text();
               context.eventsFileName += $(this).find("events").text();
           }
        });
    }   
    

提交回复
热议问题