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

Where is the initialize function for Backbone.Model documented? #4206

Open
komali2 opened this issue Oct 31, 2018 · 2 comments
Open

Where is the initialize function for Backbone.Model documented? #4206

komali2 opened this issue Oct 31, 2018 · 2 comments

Comments

@komali2
Copy link

komali2 commented Oct 31, 2018

I'm looking up how to instantiate a Backbone.Model. Under the docs for constructor / initialize, it says:

When creating an instance of a model, you can pass in the initial values of the attributes, which will be set on the model. If you define an initialize function, it will be invoked when the model is created.

What it doesn't say is what arguments that initialize function takes, which if I remember correctly includes the options object passed in on instantiation.

Where is this documented?

@jashkenas
Copy link
Owner

initialize is called at the end of the constructor function, and is passed the same arguments that you've passed to the constructor. The default implementation is to do nothing.

http://backbonejs.org/docs/backbone.html#section-51

This should, indeed, be documented slightly better.

@komali2
Copy link
Author

komali2 commented Oct 31, 2018

Oh, good to know. This also clarifies a second question I had - whether attributes passed in in the constructor were available in the initialize function. It appears they are. As in, get I do this.get('some_attribute') inside the initialize function.

@jgonggrijp jgonggrijp added this to Low priority in Dusting off Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dusting off
Low priority
Development

No branches or pull requests

3 participants