dan*_*ast 5 javascript ember.js ecmascript-6 computed-properties
可以这样:
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
})
Run Code Online (Sandbox Code Playgroud)
被改写为:
fullName: Ember.computed('firstName', 'lastName', function() {
return this.get('firstName') + ' ' + this.get('lastName');
})
Run Code Online (Sandbox Code Playgroud)
?
对我来说,这不那么模糊.每种方法的优点/缺点是什么?
后面的勾号与 Ember 无关。它们是 ES6 的一部分,称为模板字符串。它们只是让字符串插值变得更容易。您可以在花括号中包含任何有效的 js 语句,并且它们会被评估。它们还允许多行字符串。
我知道的一个要点是模板字符串会立即被评估。因此不能通过将其分配给变量来重用。变量只会得到评估结果。