0
假设我需要测试变量当我在require语句中时。如果存在,哪种方法是最好的,以便访问我需要的变量?有没有办法改变上下文?Require.js需要上下文
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';它为你捕获变量。 – Matt 2013-03-17 16:29:42