2017-08-06 4 views
0
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; 
    } 
} 

Wenn ich versuche, diesen Code auszuführen, es gibt Fehler folgende:Fehler in Prototyp-Syntax von JavaScript-Klasse

solution.js:10

Rectangle.prototype.area=funcion() {

^ SyntaxError: Unexpected token {

Antwort

1

Sie haben einen Tippfehler in dieser Zeile Rectangle.prototype.area. Sie haben function als funcion falsch geschrieben. Aktualisieren Sie es einfach und der Code wird Ihnen nicht den Syntaxfehler geben.

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; 
    } 
} 
Verwandte Themen