class Rectangle {
constructor(w, h) {
this.w = w;
this.h = h;
}
}
Rectangle.prototype.area = funcion() {
var area = this.w * this.h;
return area;
}
class Square extends Rectangle {
constructor(w){
this.w=w;
this.h=w;
}
}
当我尝试运行此代码时,它会出现以下错误:
solution.js:10
Rectangle.prototype.area = funcion(){
^ SyntaxError:意外的令牌{
答案 0 :(得分:1)
此行Rectangle.prototype.area
中有拼写错误。您的拼写错误function
为funcion
。只需更新它,代码就不会给你语法错误。
class Rectangle {
constructor(w, h) {
this.w = w;
this.h = h;
}
}
Rectangle.prototype.area = function() {
var area = this.w * this.h;
return area;
}
class Square extends Rectangle {
constructor(w){
this.w=w;
this.h=w;
}
}