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
Support ES6 method definitions for constructors #4213
Comments
i have to say, that babel converts personally, i am always using babel |
I know that using Babel solves the issue, but still I think that there's a place for this, because:
|
Using ES6, it becomes possible to extend Backbone objects using
This syntax is a nice shortcut for the more old-fashioned
The problem is though that if you want to specify a custom constructor
it turns out that
throws an
Uncaught TypeError: MyModel is not a constructor
.The reason behind this behavior is that the ES6 method definition
name()
is not completely equivalent to the oldname: function() {}
because the ES6 methods are labelled internally as non-constructable.A way to solve this is to change the extend method from
to
There is one minor drawback to this approach which is that if someone ever did something like
this would no longer work. I tried to find whether it is possible to check whether a method is constructable or not in which case something could be done like
but it seems that there's no elegant way to check this.
Hence it's a trade-off between 100% backwards compatability for a rather rare edge case, or to be able to get rid of the requirement to specify the constructor as a non-ES6 method definition, but this leads to some awkward code like
I would love to hear some thoughts on this subject. I'd be willing to create a pull request if required.
The text was updated successfully, but these errors were encountered: