如何缓存最高范围,以便以后在原型中更深入地使用,如下所示:
var Game = function(id){
this.id = id;
};
Game.prototype = {
board : {
init: function(){
// obviously "this" isn't the instance itself, but will be "board"
console.log(this.id);
}
}
}
var game = new Game('123');
game.board.init(); // should output "123"
更新:
好了,现在我考虑一下,我可以使用apply/ call并传递上下文...
game.board.init.apply(game);
侃侃无极
相关分类