class关键字
ES6中class关键字,是实现面向对象编程的新形式
class Person {
/* static 静态属性 */
static copyright = 'Gonefour_boke'
/* 静态方法 */
static fun = function () {
console.log('fun静态方法')
}
/*构造器*/
constructor (name, age, gender) {
this.name = name
this.age = age
this.gender = gender
}
/* 实例方法 */
say () {
console.log('say实例方法')
}
}
let p = new Person('boke', 18, '男') /* 实例化一个Person */
console.log(p) /* 实例属性 */
p.say() /* 实例方法 */
console.log(Person.copyright) /* 静态属性 */
Person.fun() /* 静态方法 */
控制台打印输出内容(console)
class
总结
在class关键字的{}区间内,只能写构造器(constructor)、静态方法和静态属性(static)、实例方法