Inc1982
Inc1982

Reputation: 1975

What do I get with the default Backbone.Model initialize function?

For context I use coffeescript. If I create a base model that extends Backbone.Model and I create another class (i.e. App.Models.Project extends App.Models.Base).. everything works as expected.. what would be the difference to an instance of Project if in this base class I wrote:

initialize: ->
  super
  console.log 'hi'

and just plain

initialize: ->
  console.log 'hi'

Without spending too much time, it seems in my console an instantiated object acts as expected in both cases.. I hear you should 'always call super' here but I don't know what I'm getting..

Upvotes: 0

Views: 61

Answers (1)

Pramod
Pramod

Reputation: 5208

Backbone.Model.initialize does nothing.

From the annotated source code, you can see the empty function defined in Backbone.Model

initialize: function(){}

It's upto your model to override. Usually, model variables are set here. Whenever you create a model object, initialize is called internally.

The same principle holds good when creating Views and Collections too.

Upvotes: 1

Related Questions