首先做个简单的示例
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('小李');
上面代码原型示意图
1513411452199_2.png
网友评论