Backbone.js Model Constructor / Initialize

The Backbone.js initialize function is invoked by a class constructor while a model instance is created.

When model instance is created, the class's constructor gets called.

Syntax:

Parameter explanation:

attributes: Attributes define properties of a model, when creating instance of that model.

options: These are the options such as id, name etc used with attributes when model is created.

Let's take an example.

See this example:

Test it Now

Output:

Save the above code in initialize.html file and open this file in a new browser.

BackboneJS Event Initializ Model
Next TopicBackbone.js Get