CNode

es6 类声明

问答
Ooyosc发布于10 年前最后回复10 年前5 回复4772 浏览0 收藏

class Polygon { constructor(height, width) { this.height = height; this.width = width; } } 为什么height跟width不需要声明呢

查看回复

回复 (4)

I
im-here#1·10 年前

你说的是this.height 和this.width吧,因为这是给一个Object增加属性啊

S
scarletmu#2·10 年前

这是class的构造函数,this.xxx就是为你调用new Polygon(height,width)这个构造函数时初始化class内的值

J
jingsam#3·10 年前

哈哈,看来楼主是从java或C#转过来的,还不适应javascript的方式

参与回复
登录后即可参与回复。登录