这两个代码之间的最佳做法是什么?
1 - 使用变量隐藏复杂性并避免重复多次完整上下文
class FooController {
myFunction(request, resolve, reject) {
const lang = this.context.lang;
const FooService = request.context.services.FooService;
// use the variable lang multiple times (2 times to 10 times)
FooService.getFoo().then(data => {
data[lang] = "foo";
resolve(data[lang]);
}.catch(reject);
}
}
2 - 重复多次变量的完整上下文
class FooController {
myFunction(request, resolve, reject) {
request.context.services.FooService.getFoo().then(data => {
data[this.context.lang] = "foo";
resolve(data[this.context.lang]);
}.catch(reject);
}
}