目标是允许全局变量(例如currentAccount
)根据执行上下文同时引用多个值。
var context = new Context();
context.currentAccount = "mine";
context.execute(function() {
// any code in or called by this function
// needs access to the `currentAccount` variable
// for example
var model = new Model();
model.doSomething(); // model needs to be able to refer to `currentAccount`
});
context = new Context();
context.currentAccount = "yours";
context.execute(function() {
...
model.doSomething(); // `currentAccount` => "yours"
});