Why is my variable undefined inside the Underscore.js each function?

前端 未结 4 639
無奈伤痛
無奈伤痛 2021-02-05 08:32

Here is my code:

TextClass = function () {
    this._textArr = {};
};

TextClass.prototype = {
    SetTexts: function (texts) {
        for (var i = 0; i < te         


        
4条回答
  •  [愿得一人]
    2021-02-05 08:48

    Note that you can also pass things other that "this". For example, I do something like:

    var layerGroupMasterData = [[0],[1,2,3],[4,5],[6,7,8,9],[10]];
    
    _.each(layerGroupMasterData,function(layerGroup,groupNum){
        _.each(layerGroup, function (layer, i) {
                doSomethingThatComparesOneThingWithTheOverallGroup(layerGroupMasterData,layer);
        },layerGroups);
    },layerGroupMasterData);
    

提交回复
热议问题