-
Notifications
You must be signed in to change notification settings - Fork 950
WidgetModel.__super__.constructor should be called last #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WidgetModel.__super__.constructor should be called last #266
Conversation
Shoot, we may have problems when doing this in Babel and/or Typescript. IIRC both require you to call super in the constructor before anything else. |
How come? |
Typescript doesn't insist that super is called first, only that it is called: http://www.typescriptlang.org/Playground#src=class%20A%20%7B%0A%09constructor()%20%7B%0A%09%09this.a%20%3D%201%3B%0A%09%7D%0A%09a%3A%20number%3B%0A%7D%0A%0Aclass%20B%20extends%20A%20%7B%0A%09constructor()%20%7B%0A%09%09this.a%20%3D%202%3B%0A%09%09super()%3B%0A%09%7D%0A%7D |
Besides, that is only for classes written in typescript. This is about classes written using Babel's class structure, which may be very different. |
Regardless, we should just keep this in mind. We can find a workaround if we need to when we need to. 👍 to merge as-is. |
@jdfreder isn't ES6 class |
Honestly, I don't know how backbone interprets its |
I just thought that it was a coincidental thing that both were called |
WidgetModel.__super__.constructor should be called last
Possibly |
fyi, typescript does something similar to Babel: http://www.typescriptlang.org/Playground#src=class%20A%20%7B%0A%09constructor()%20%7B%0A%09%09this.a%20%3D%201%3B%0A%09%7D%0A%7D%0A Actually, it does look like Backbone does something similar: http://backbonejs.org/docs/backbone.html#section-248 |
__super__.constructor
is the function callModel.initialize
. We need everything that is in constructor to be done before initialize otherwise, we cannot call model.set in initialize.The reason is that we overload
Model.set
and our overloaded method uses attributes set inconstructor
.