<script>
/**该例子用于动态模仿继承*/
//定义父类
function Farent(name,age)
{
this.name = name;
this.age = age;
this.say = function ()
{
alert("name:"+this.name + "~~age:"+this.age);
}
}
//定义子类 关键方法call
function Child(name,age,work)
{
Farent.call(this,name,age);
this.work = work;
//定义相同方法,就会覆盖父类Farent方法
this.say = function()
{
alert("name:"+this.name + "~~age:"+this.age+"~~work:"+this.work);
}
}
var farent = new Farent("parent",27);
var child = new Child("child",1,'desi');
farent.say();
child.say();
</script>