Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Adds Native Class Constructor Update write-up to blog #3417

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion source/blog/2018-06-22-the-ember-times-issue-52.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@ Read either on the [Ember blog](https://www.emberjs.com/blog/2018/06/22/the-embe

---

## [SECTION TITLE](section url)
## [Native Class Constructor Update 🛠](https://github.com/emberjs/rfcs/pull/337)

There is currently an open RFC proposing to change the behavior of `EmberObject's` constructor.

Native class syntax with EmberObject has almost reached full feature parity, meaning soon Ember will be able to ship native classes.
However, early adopters of native classes have experienced some serious issues due to the current behaviour of the class constructor. The issue is caused by the fact that properties passed to `EmberObject.create` are assigned to the instance in the root class `constructor`. Due to the way that native class fields work, this means that they are assigned _before_ any subclasses' fields are assigned, causing subclass fields to overwrite any value passed to `create`.

The new implementation of the Ember Object would look like the following:

```js
class EmberObject {
constructor(props) {
// ..class setup things
}

static create(props) {
let instance = new this(props);

Object.assign(instance, props);
instance.init();

return instance;
}
}
```

This would assign the properties _after_ all of the class fields for any subclasses have been assigned.

One thing worth mentioning is that EmberObject will likely be deprecated in the near future and that ideally for non-Ember classes (things that aren't Components, Services, etc.) users should drop EmberObject altogether and use native classes only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be cool to add a final call-to action as well, reminding people that they can comment on the RFC to help finalizing it - what do you think?

:point_right: As always, all comments to this RFC are more than welcome, so let's help out in order to finalize it! :sparkles:


---
Expand Down