我试图获取在方法下使用的默认值.似乎Model.get()不能在方法本身内使用.我试过了两个console.log,它显示的变量没有定义.
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;
});
Run Code Online (Sandbox Code Playgroud)
根据你的问题(获取默认值),答案应该是
this.defaults.numBlockTypes
Run Code Online (Sandbox Code Playgroud)
提到的方法
this.get("numBlockTypes")
Run Code Online (Sandbox Code Playgroud)
返回当前(设置)值.
小智 2
@Elvis D'Souza 和我同时得出了相同的答案。
需要报价
console.log(this.get('numBlockTypes'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6397 次 |
| 最近记录: |