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);
The correct syntax you want to get the ‘index’ attribute is:
get() takes a string of the attribute name.
Here’s the Backbone doc section