後でプロトタイプでより深く使用するために、最上位のスコープをキャッシュする方法は次のとおりです。
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);