Getting default values ​​from Backbone.Model in method?

I am trying to get default values ​​for use as part of a method. It seems that Model.get() cannot be used in the method itself. I tried two console.log , which shows that the variable is not defined.

 define(['jquery', 'Underscore', 'Backbone'], function($, _, Backbone){ var Game = Backbone.Model.extend({ //default values for the function defaults: { rows : 9, cols : 8, baseScore : 100, numBlockTypes : 6, baseLevelTimer : 60000, baseLevelScore : 1500, baseLevelExp : 1.05, }, initialize: function(){ console.log(this.get(numBlockTypes)); //console.log(numBlockTypes); } }), game = new Game; return game; }); 
+7
source share
2 answers
And Elvis D'Souza and I answered at the same time.

Quotes are needed

 console.log(this.get('numBlockTypes')); 
+2
source

According to your question (get the default values ) the answer should be

 this.defaults.numBlockTypes 

Mentioned method

 this.get("numBlockTypes") 

returns current (set) values.

+5
source

All Articles