我经常看到Ember.js中的代码使用对象破坏来检索函数
const { computed } = Ember;
如果这种模式有优势而不是直接调用Ember.computed
而不是减少代码?这是否会反对在对象中封装函数?
答案 0 :(得分:1)
除了每次只需编写computed
而不是Ember.computed
之外(仅肯定会为许多用法付出代价),主要优势是computed
成为本地和const
变量。这可以加快变量查找时间,而不需要搜索Ember
的全局范围。它还可以通过覆盖Ember.computed
来防止有人弄乱您的代码,具体取决于您的模块在解密结构中的确切位置。