1. 首页
  2. 编程面试题
  3. 前端
  4. ES6

ECMAScript 6 怎么写 class ,为何会出现 class?



ES6的class可以看作是一个语法糖,它的绝大部分功能ES5都可以做到,新的class写法只是让对象原型的写法更加清晰、更像面向对象编程的语法。

js
//定义类
class Point {
constructor(x,y) {
//构造方法
this.x = x; //this关键字代表实例对象
this.y = y;
} toString() {
return '(' + this.x + ',' + this.y + ')';
}
}

发布者:admin,如若转载,请注明出处:https://ai1024.vip/29002.html

QR code
//