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
Add getter/setter support to extend method #3483
Comments
Is there any reason that couldn't be better written as Using getters and setters are for the most part a bad idea in JS, and they go against one of the core ideas of Backbone Models. I doubt you'll see support added anytime soon. |
More than anything this would be partially aligned with the new class syntax. There are no property initializers in the class syntax or even any spec for them yet, so interop will be an issue.
What core idea is that? Also getters are a partial solution to an existing problem in Backbone.Collection with |
Spent a few minutes trying to make a jsperf with different solutions: |
The idea that setting and retrieving a property on an object should be transparent and logical to reason about. You should always know that
Any reason the current |
Sorry I should've linked to the issue I was speaking about: #3408 I'm bringing this up mainly because Backbone's class syntax is largely already compatible with the ES class syntax, and it seems only reasonable they be compatible considering the added support for coffeescript. |
CoffeeScript doesn't support setters and getters largely for the same reasons (look into issues there for some background, starting with jashkenas/coffeescript#2902). They shouldn't be a roadblock to supporting Backbone objects as classes.
Remind me? I'm straining to see the connection off the bat. Besides, any changes to |
I wasn't speaking about getters/setters, I was speaking about how Backbone added
Collection.extend({
model: function() { return Model }
});
//
collection.modelId(model); // 'id' regardless if that's correct or not. Collection.extend({
get model() { return Model }
});
//
collection.modelId(model); // correct for *some* of the common cases.
That's definitely not the right place for this change, if anything it would be in the new Also, before this issue gets closed and forgotten about I would like to address why it's okay for Backbone's extend to have the interop issues with ES classes but not CoffeeScript classes. |
Well seeing as IE Tech Preview is the only browser with even remotely decent support of |
They both do actually, they just require support for Also there is no reason backwords-compatibility needs to be broken, it could even be made faster if it selectively used |
@thejameskyle Want to turn this into a PR instead of an issue? It's worth looking at. |
Sure, I'll do that |
Is it on the way ? Have you a gist or something about it ? I'd like to take a shot. |
Since getters/setters are supported IE9+ and will be much more prevalent with ES6 it'd be nice if Backbone's extend method supported them.
Right now this would result in
undefined is not a function
because using_.extend
is calling the getter.The text was updated successfully, but these errors were encountered: