function Human(options){
this.name = options.name;
this.city = options.city;
this.__proto__ = Human.prototype;
} // 构造函数结束
Human.prototype.species = 'people';
Human.prototype.walk = function () {
console.log(this.name + ' walking in ' + this.city);
}
Human.prototype.useTools = function () {
console.log('useTools');
}
var human = new Human({name:'Frank', city: 'Hangzhou'})
var human2 = new Human({name:'Jack', city: 'Hangzhou'})
console.log(human.species + ': ' + human.name);
console.log(human.species + ': ' + human2.city);
human.walk();
console.log(human.__proto__.constructor === Human);
output:
people: Frank
people: Hangzhou
Frank walking in Hangzhou
true
网友评论