相关疑难解决方法(0)

Javascript:Function和Class之间有什么区别

随着2015年6月ECMAScript 6的发布,引入了Javascript类语法.

这个语法:

class Polygon {
      constructor(width, height) {
        this.width = width;
        this.height = height;
      }
}
Run Code Online (Sandbox Code Playgroud)

基本相同:

function Polygon(width, height) {
    this.width = width;
    this.height = height;
}
Run Code Online (Sandbox Code Playgroud)

那么使用类而不是传统函数有什么好处呢?在什么条件下我应该使用类而不是函数?

javascript ecmascript-6

11
推荐指数
1
解决办法
4075
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1