backbone
backbone copied to clipboard
Where is the initialize function for Backbone.Model documented?
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?
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.
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.