function extend(sub,sup)
{
//目地:实现只继承父类的原型对象
//1.用一个空函数据中转,目地进行中转
var F = new Function();
//2.实现空函数的的原型对象和超类的原型对象转换
F.prototype = sup.prototype;
//3原型继承
sub.prototype =sup.prototype;
//4.还原子类的构造器
sub.prototype.constructor = sub;
//5.保存父类的原型对象 一方面解耦,另一方面可以方便获得父类的原型对象
sub.superClass = sup.prototype;
}
function People(name,age)
{
this.name = name;
this.age = age;
}
People.prototype=
{
constructor:People,
sayHello:function()
{
alert('hello word')
}
}
function Boy(name,age,sex)
{
//People.call(this,name,age);
Boy.superClass.constructor.call(this,name,age);
this.sex = sex;
}
extend(Boy,People);
People.prototype=
{
sayHello:function()
{
alert('badd')
}
}
var b = new Boy('张三','21','男')
alert(b.name);
alert(b.age);
alert(b.sex);
b.sayHello();