var Game = function(){
var game = this;
game.Player = {
pts:[]
}
}
例如在php中它可以是:
game.Computer extends game.Player
但是如何在game.Player中使用javascript在同一个类中做一个孩子?
[update]
[1]
var Game = function(){
var game = this;
game.Player = {
pts:[],
test: function(){ alert('test'); }
}
Player.prototype = new Computer;
game.Computer = {
}
}
var game = new Game();
game.Computer.test();
我不确定@BenM
[update]
[2]
甚至是这样:
var Game = function(){
var game = this;
game.Player = {
pts:[],
test: function(){ alert('test'); }
}
game.Player.prototype = game.Computer {
}
}
var game = new Game();
game.Computer.test();
这也是错误的,不能按原样延伸。对不起,如果这里有很多代码。
答案 0 :(得分:0)
您似乎正在寻找有关如何在JavaScript中进行继承的基本教程。这是一个很好的:http://www.klauskomenda.com/code/javascript-inheritance-by-example/