class Polygon { constructor(height, width) { this.height = height; this.width = width; } } 为什么height跟width不需要声明呢
回复 (4)
I
你说的是this.height 和this.width吧,因为这是给一个Object增加属性啊
S
这是class的构造函数,this.xxx就是为你调用new Polygon(height,width)这个构造函数时初始化class内的值
J
哈哈,看来楼主是从java或C#转过来的,还不适应javascript的方式
C
引用 jingsam哈哈,看来楼主是从java或C 转过来的,还不适应javascript的方式
@jingsam 蛤蛤,javascript随时都能this出新的东西
参与回复
登录后即可参与回复。登录