function Prents(Uname){
this.Uname = Uname;
}
Prents.prototype.run =function(){
return this.Uname;
}
function Child(sex){
this.sex = sex;
}
Child.prototype = new Prents("zhagnsan");
var childDemo = new Child("nv");
alert(childDemo.sex)
alert(childDemo.Uname);
alert(childDemo.run());
我们可以清楚的看到,可以继承到父类的实例里变量,原型里的方法,变量等所有信息!
我们来分析:首先我们前面说过prototype属性是个对象所以我们 Child.prototype = new Prents("zhagnsan");前面说过每一个实例对象都有一个--proto--属性指向他的原型,然后这个原型里面有个属性constructor的值是构造函数的内容(就是指向了那个构造函数)
注意:实际的开发过程中我们利用组合的方法实现继承,利用call,appy+原型链和其他的模式