Skip to content
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

Unexpected behavior if you try to treat backbone model instances in a classical OO fashion #1262

Closed
jdkanani opened this issue Apr 30, 2012 · 2 comments

Comments

@jdkanani
Copy link
Contributor

See the snippet @ http://jsfiddle.net/ZxuFQ/4/

We would traditionally expect that hashmap2 would contain only the values {4,5,6}. However it contains {1,2,3,4,5,6}

Surprisingly if you do this:

http://jsfiddle.net/SaaJz/4/

the behavior is as one would expect!

@jashkenas
Copy link
Owner

It's JavaScript. Properties on the prototype are shared by reference ... just like class-level properties would be shared the same way in Ruby.

If you'd like to have a different hash for each instance, define defaults as a function, as documented.

@braddunbar
Copy link
Collaborator

Hi @jdkanani, thanks for your issue. This is already being discussed in #476. Would you mind directing further comments there? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants