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

Add comment about calling _super when overriding init #239

Merged
merged 1 commit into from
Jan 26, 2015
Merged

Add comment about calling _super when overriding init #239

merged 1 commit into from
Jan 26, 2015

Conversation

mattmcginnis
Copy link
Contributor

I'm using init in my controller for something unrelated to validations and was receiving errors related to validations. It took me a while to figure out it was due to overriding init. The docs mention calling _super, but only related to creating your own validator, so when investigating, I skipped that section thinking it was unrelated.

@bcardarella
Copy link
Contributor

The order of this._super() is also important. In almost all cases it should be called first.

@bcardarella
Copy link
Contributor

@mattmcginnis actually, I think this is implied with how you wrote the comments. Thanks!

bcardarella added a commit that referenced this pull request Jan 26, 2015
Add comment about calling _super when overriding init
@bcardarella bcardarella merged commit 010a66a into DavyJonesLocker:master Jan 26, 2015
export default Ember.ObjectController.extend({
init: function() {
// this call is necessary, don't forget it!
this._super();

Choose a reason for hiding this comment

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

for < es6

this._super.apply(this, arguments)

for es6

this._super(...arguments);

Copy link
Contributor

Choose a reason for hiding this comment

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

@stefanpenner will the es5 version work with es6?

Choose a reason for hiding this comment

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

yup

@stefanpenner
Copy link

The order of this._super() is also important. In almost all cases it should be called first.

good rule of thumb is, if you are not sure, calling super should be the first time you access this. So think of super in a constructor as a way to prepare the this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants