原型链继承关系小demo
function SuperType() {
this.property = true;
this.name = "lisi";
}
SuperType.prototype.getSuperValue = function () {
return this.property;
};
function SubType() {
this.subproperty = false;
}
//继承了 SuperType
SubType.prototype.aa = '132';
SubType.prototype = new SuperType();
SubType.prototype.getSubValue = function () {
return this.subproperty;
};
console.log(SubType.prototype.constructor)
var instance = new SubType();
console.log(instance);
console.log(instance.getSuperValue()); //true
console.log(instance.getSubValue()); //false
console.log(instance.aa); //undefined
console.log(instance.name); //lisi
var cc = new SuperType();
console.log("----分割线----");
console.log(cc);
console.log(cc.getSuperValue()); //true
console.log(cc.getSubValue()); //报错
function FOO() {
this.rename = 'zhangsan'
}
FOO.rename = 'wangwu';
FOO.prototype.rename = 'lisi';
var c = new FOO();
console.log(c)