【发布时间】:2013-03-05 23:36:40
【问题描述】:
假设当我在 require 语句中时需要 test 变量。如果存在,为了访问我需要的变量,哪种方法是最好的?有没有办法改变上下文?
somefunction: function(id) {
var test ="xxx";
require(['models/Model', 'views/View'], function(ArticleModel, ArticleView) {
var collection = new Collection();
// I need to access the TEST variable HERE
});
}
【问题讨论】:
-
就用吧。它会在那里。阅读 JavaScript
closures;它会为您捕获变量。
标签: javascript scope requirejs require