JavaScript logoJavaScript/
JS-0774

Should not use Arrow functionsJS-0774

Minor severityMinor
Bug Risk categoryBug Risk
ember

Arrow functions should not be used in computed properties because they are unable to access other properties (using this.property) of the same object. Accidental usage can thus lead to bugs.

Bad Practice

import EmberObject, { computed } from '@ember/object';

const Person = EmberObject.extend({
  fullName: computed('firstName', 'lastName', () => {
    return `${this.firstName} ${this.lastName}`;
  })
});
import EmberObject, { computed } from '@ember/object';

const Person = EmberObject.extend({
  fullName: computed('firstName', 'lastName', function () {
    return `${this.firstName} ${this.lastName}`;
  })
});