【发布时间】:2015-09-08 02:59:40
【问题描述】:
http://www.es6fiddle.net/iearlj80/
你好 我正在尝试学习 ES6。但是我收到了错误 TypeError: a.area is not a function at eval 为什么?其实我是这样调用函数函数的
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea()
}
calcArea() {
return this.height * this.width;
}
}
var a =new Polygon(10,20)
alert(a.area())
当我像这样使用 a.calcArea() 时它可以工作,但是当我像这样使用 a.area() 时它会出错?为什么 ?
【问题讨论】:
-
为什么你在一个定义中使用
get而不是另一个?也许这就是为什么有区别......
标签: javascript jquery ecmascript-6