對不起,如果是重複的,但我沒有找到解釋。 如何在js類中創建字段?以定義未來...如何在javascript類中訪問字段
class Polygon {
//var whyNot; This makes false
constructor(height, width) {
this.height = height;
this.width = width;
}
calcArea() {
return this.height * this.width;
}
}
? – War10ck
我不這麼認爲 - 我在這裏找到了這個例子https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes,我試圖學習清晰的文檔。 – nolbadi111
這個例子是ES6。我已將標籤添加到您的問題中,以提高其可見度。 – War10ck