function People(name, age) {
this.name = name;
this.age = age;
People.count++
}
People.prototype.showName = function() {
console.log(this.name)
}
// 静态属性
People.count = 0;
// 静态方法
People.getCount = function() {
console.log("共有"+People.count+"人!");
}
let p1 = new People('tom', 11);
p1.showName();
let p2 = new People('jack', 18);
p2.showName();
People.getCount();
function Animal(name) {
this.name = name;
}
Animal.prototype.showName = function() {
console.log(this.name);
}
function Dog(name, color) {
Animal.call(this, name);
this.color = color;
}
Dog.prototype = new Animal();
let dog = new Dog('xx', 'white');
dog.showName();
console