首先做個簡單的示例
function People (name){
this.name = name;
this.sayName = function(){
console.log('my name is:' + this.name);
}
}
People.prototype.walk = function(){
console.log(this.name + ' is walking');
}
var p1 = new People('小明');
var p2 = new People('小李');
上面代碼原型示意圖