从ES6开始系统提供了一个名称叫做class的关键字, 这个关键字就是专门用于定义类的
class Person {
// 当我们通过new创建对象的时候, 系统会自动调用constructor
constructor (name, age) {
this.name = name;
this.age = age;
this.say = function () {
console.log(this.name, this.age);
}
}
// 定义到了原型上
say () {
console.log(this.name, this.age);
}
// 静态属性 不能这样定义 大多浏览器不支持
// static num = 12;
// 静态方法
static std () {
console.log('我爱学习!');
}
}
// 定义静态属性
Person.num = 12;
let per = new Person('菜墟琨', 12);
console.log(per.name);
per.say();
console.log(Person.num);
Person.std();