Skip to content

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

Merged
merged 1 commit into from
Dec 11, 2015

Conversation

SylvainCorlay
Copy link
Member

__super__.constructor is the function call Model.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 in constructor.

@jdfreder
Copy link
Contributor

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.

@SylvainCorlay
Copy link
Member Author

How come?

@jasongrout
Copy link
Member

Besides, that is only for classes written in typescript. This is about classes written using Babel's class structure, which may be very different.

@jdfreder
Copy link
Contributor

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 jdfreder added this to the 5.0 milestone Dec 11, 2015
@SylvainCorlay
Copy link
Member Author

@jdfreder isn't ES6 class constructor a completely different thing from backbone model's constructor method?

@jdfreder
Copy link
Contributor

@jdfreder isn't ES6 class constructor a completely different thing from backbone model's constructor method?

Honestly, I don't know how backbone interprets its constructor key, but babel compiles constructor to what you'd expect: https://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=class%20A%20%7B%0A%09constructor()%20%7B%0A%09%09this.a%20%3D%201%3B%0A%09%7D%0A%7D%0A . I'd assume backbone did the same, but you're saying it doesn't?

@SylvainCorlay
Copy link
Member Author

I just thought that it was a coincidental thing that both were called constructor.

jdfreder added a commit that referenced this pull request Dec 11, 2015
 WidgetModel.__super__.constructor should be called last
@jdfreder jdfreder merged commit 896f1da into jupyter-widgets:master Dec 11, 2015
@jdfreder
Copy link
Contributor

Possibly

@SylvainCorlay SylvainCorlay deleted the model_constructor branch December 11, 2015 18:32
@jasongrout
Copy link
Member

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

@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants