标签:cto this logs struct style func span tor air
class的数据类型为function,可以看做构造函数的另一种写法。事实上,类的所有方法都定义在类的prototype属性上面。
一、声明class
class Animal { constructor(eye,hair) { this.eye = eye; this.hair = hair; } speak() { console.log(`我有${this.eye}的眼睛和${this.hair}的头发。`) } } let ains = new Animal(‘black‘,‘white‘) ains.speak();
二、class表达式
let person = new class { constructor(name) { this.name = name; } sayName() { console.log(this.name); } }(‘张三‘); person.sayName(); // "张三"
标签:cto this logs struct style func span tor air
原文地址:http://www.cnblogs.com/camille666/p/es_class.html