javascript的prototype的一则应用实例

function person(name)
{
this.name=name;
}
person.prototype.sayHello=function(){alert("hello,my name is "+this.name);};

var mark=new person("mark");
mark.sayHello();// hello,my name is mark

function game(name,game)
{
 person.call(this,name);
 this.game=game;
}
[!--
var mark=new game("mark","War3");
mark.sayHello();//错误
--]
game.prototype=new person();
[!--
var mark=new game("mark","War3");
mark.sayHello();//hello,my name is mark
--]

posted on 2011-04-12 22:36  梵唱狂歌  阅读(134)  评论(0)    收藏  举报

导航