Skip to content

Commit

Permalink
Merge pull request #269 from ember-learn/deprecate-alias-method
Browse files Browse the repository at this point in the history
Adds aliasMethod deprecation
  • Loading branch information
rwjblue authored Feb 2, 2019
2 parents f4c425f + 38649be commit 67023c5
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions content/ember/v3/deprecate-alias-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: object.alias-method
title: Deprecate `@ember/object#aliasMethod`
until: '4.0.0'
since: '3.8'
---

`@ember/object#aliasMethod` is a little known and rarely used method that allows
user's to add aliases to objects defined with `EmberObject`:

```js
import EmberObject, { aliasMethod } from '@ember/object';

export default EmberObject.extend({
foo: 123,
bar() {
console.log(this.foo);
},
baz: aliasMethod('bar'),
});
```

This can be refactored into having one function call the other directly:

```js
import EmberObject from '@ember/object';

export default EmberObject.extend({
foo: 123,
bar() {
console.log(this.foo);
},
baz() {
this.bar(...arguments);
},
});
```

Avoid defining methods directly on the class definition, since this will not
translate well into native class syntax in the future:

```js
// Do not use this, this is an antipattern! 🛑
import EmberObject from '@ember/object';

function logFoo() {
console.log(this.foo);
}

export default EmberObject.extend({
foo: 123,
bar: logFoo,
baz: logFoo,
});
```

0 comments on commit 67023c5

Please sign in to comment.