js原型链讲解

function Man(name,age) {

this.name = name;

this.age = age;

}

function test() {

var person1 = new Man("张三","18");

var person2 = new Man("李四","19");

Man.prototype.sex = "男";

console.log(person1.sex); //男

console.log(person2.sex); //男

}


function FutherType(){

this.property = true;

}

FutherType.prototype.getFutherValue - function(){

return this.property;

}

function SonType(){

this.sonproperty = false;

}

SonType.prototype = new FutherType();

SonType.prototype.getSonValue = function(){

return this.sonproperty;

}

var instance = new SonType();

console.log(instance.getFutherValue()); //true


你可能感兴趣的:(js原型链讲解)