-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Collection.get returns Object.prototype methods #2973
Comments
Hey @jthoms1, this has been brought up a few times before (do a search through past tickets). Unfortunately thats the tradeoff when using an object to store these keys. Dont allow arbitrary values for your ids (and stick with numeric, unique, and sequential ids) and you should be fine. |
Since there is already get: function(attr) {
return this.attributes['somePrefix' + attr];
} or better yet as @jthoms1 suggested using get: function(attr) {
return _.has(this.attributes, attr) ? this.attributes[attr] : void 0
} with the same thing done in the |
@Dw40 that doesnt seem like a good solution for either Model or Collection to me (too much overhead -- cognitive and otherwise). See other threads for more discussion and some suggestions. |
Apologizes, I did not see previous tickets. Issue #2719 covers my exact scenario. I was going to ask for a documentation update but alas current documentation references "(integer id or UUID)" to be used as model IDs. Thanks |
No problem. Thats what its there for :)
|
Currently Backbone.Collection is using an object to keep track of models that exist within that collection. It should probably be using 'hasOwnProperty' instead to avoid returning methods from Object.prototype.
The issue originally occurred for me in Firefox when I had a model id of 'watch' and backbone refused to add it to a new collection. This was using 0.9.9 but it appears the issue exists within the latest version as well.
I have a jsbin to demonstrate the issue with 'valueOf'.
http://jsbin.com/OmeBAW/3/edit
The text was updated successfully, but these errors were encountered: