首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >jQuery each()闭包-如何访问外部变量

jQuery each()闭包-如何访问外部变量
EN

Stack Overflow用户
提问于 2012-09-07 06:21:12
回答 3查看 26.3K关注 0票数 21

从$.each()中访问this.rules变量的最佳方式是什么?任何解释为什么/如何也是有帮助的!

app.Style = function(node) {
    this.style = node;
    this.rules = [];
    var ruleHolder = node.find('Rule');

    $.each(ruleHolder, function(index, value) {
        var myRule = new app.Rule($(ruleHolder[index]));
        this.rules.push(myRule);
    });

    console.log(this.rules)
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12309264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档