-
-
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
TypeError: existing.set is not a function #4224
Comments
This seems like an odd thing to fix. This to me seems unlikely in general, but fixing it would add at least some cost to most actions across backbone where this issue is never likely to arise. If anything the best fix to me seems to be something like adding to the docs " |
Can also cause the same bug by setting it to a different attribute and then setting idAttribute of the model to that, e.g:
Agree it's an edge case, but I think it's a valid use case if the string is a valid unique identifier in the database |
As far as I'm concerned, this isn't specific to Backbone; it's on the list of things you should do nowhere in JavaScript. Of course, it's fine if you learn by experimentation that doing stuff like this breaks things, but this doesn't need documentation in Backbone, let alone a fix. As for unique identifiers in databases, I expect those to be serial numbers or something more advanced like a UUID. Certainly not names of JavaScript's global object methods. |
In
Collection#set
, it does:var existing = this.get(model);
which in this case is settingexisting
toObject#hasOwnProperty
rather thanundefined
becauseCollection#get
is returning the result ofthis._byId['hasOwnProperty']
Have reproduced this bug in a codepen here.
The text was updated successfully, but these errors were encountered: