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

minor mistake on nested attributes example #189

Open
renatoargh opened this issue Aug 14, 2014 · 2 comments
Open

minor mistake on nested attributes example #189

renatoargh opened this issue Aug 14, 2014 · 2 comments

Comments

@renatoargh
Copy link

Hey!!! First; thank you for your awesome work, second; it seems that this line has a minor mistake:

Actual:

model = new Backbone.DeepModel({firstName:'Bob', ...

With correction:

model = new Backbone.DeepModel.extend({firstName:'Bob', ...

Thanks again!

@platinumazure
Copy link
Contributor

Hi @renatoargh, thanks for the note.

Are you sure this is a mistake? Backbone.DeepModel is defined as a Backbone.Model.extend() result, meaning it "is-a" Backbone.Model constructor and that result can be called with new up with a set of attributes in its constructor.

Backbone.DeepModel.extend(), on the other hand, creates a new model type (which "is-a" Backbone.DeepModel and "is-a" Backbone.Model transitively). That expression also returns a constructor.

Calling new on a call to extend feels very weird here. Are you quite sure that's the correct way to go? (JS will parse that as new (Backbone.DeepModel.extend)(/* params */), I think, and if it works, it only works through pure luck.

Related: Some people forget that you can in fact directly create a Backbone.Model:

var myModel = new Backbone.Model({ attr1: "attr1" });

@renatoargh
Copy link
Author

@platinumazure to be honest its been a long time since I had this problem by following the example so I can't really remember the context. I think that JS would parse my correction like this (but if not, thats what I should have written instead);

var Model = Backbone.DeepModel.extend({firstName:'Bob', ...
new Model();

Thanks for your answer, these plugins are both absolute awesomeness :)

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

2 participants