Mark
Mark

Reputation: 521

Extremely simple error with backbone.js throwing invalid object initializer error

Okay, I try to avoid posting silly questions, but I can't figure out this error and if it's this subtle it may help other people anyway.

What is wrong with this code:

(function($){


var Item=Backbone.Model.extend({
  defaults: {
    ItemName:'Item ',
    counter:0,
    index:0,
    allSetView:'',
    Set: []
  },
  initialize: function(){
  alert('youve created a new item');
  }
});

var item=new Item();
alert(item.get({"index"}));//error thrown here
})(jQuery);

Upvotes: 0

Views: 157

Answers (1)

DigTheDoug
DigTheDoug

Reputation: 1440

The correct syntax you want to get the 'index' attribute is:

item.get("index")

get() takes a string of the attribute name.

Here's the Backbone doc section

Upvotes: 1

Related Questions