我是requirejs的新手并且不了解变量范围。
所以以前,例如,我有:
var Foo = "some value";
function firstFunction () {
//do something with Foo here
console.log(Foo);
}
function secondFunction () {
//do something else with Foo here
console.log(Foo);
}
但在模块中
define(function() {
return {
//how do I declare Foo within the module so it is available to firstFunction and secondFunction?
firstFunction: function() {
//do something with Foo here
console.log(Foo);
},
secondFunction: secondFunction () {
//do something else with Foo here
console.log(Foo);
}
}
});
有没有办法在模块中声明变量Foo并使其可用于firstFunction()和secondFunction()?