Baseline Widely available
class
ì ì¸ì íë¡í íì
ê¸°ë° ììì ì¬ì©íì¬, 주ì´ì§ ì´ë¦ì ìë¡ì´ í´ëì¤ë¥¼ ë§ëëë¤.
class Polygon {
constructor(height, width) {
this.area = height * width;
}
}
console.log(new Polygon(4, 3).area);
// Expected output: 12
í´ëì¤ ííì ì¬ì©íì¬ í´ëì¤ë¥¼ ì ìí ìë ììµëë¤. ííìê³¼ ë¬ë¦¬ ì ì¸ë¬¸ì¼ë¡ë ê°ì í´ëì¤ë¥¼ ë¤ì ì ì¸íë©´ ì¤ë¥ê° ë°ìí©ëë¤.
구문 class name [extends] {
// class body
}
ì¤ëª
í´ëì¤ ë³¸ë¬¸ì ì격 모ëìì ì¤íë©ëë¤. ìì±ì ìì±ì ì í ì¬íì ëë¤..
í´ëì¤ ì ì¸ì í¨ì ì ì¸
ê³¼ ë¬ë¦¬ í¸ì´ì¤í
ì ëìì´ ìëëë¤.
ë¤ì ìì ë ì°ì Polygon
í´ëì¤ë¥¼ ì ìíê³ , Square
ë¼ë ì´ë¦ì ìë¡ì´ í´ëì¤ê° Polygon
ì ììí©ëë¤. ìì±ì ë´ë¶ì super()
ë ìì±ì ë´ììë§, ê·¸ë¦¬ê³ this
í¤ìë를 ì¬ì©í기 ì ìë§ ì¸ ì ìë¤ë ì ì 주ìíì¸ì.
class Polygon {
constructor(height, width) {
this.name = "Polygon";
this.height = height;
this.width = width;
}
}
class Square extends Polygon {
constructor(length) {
super(length, length);
this.name = "Square";
}
}
ê²½ê³ : ê°ì í´ëì¤ë¥¼ ë ë² ì ì¸íë ¤ê³ ìëí ë í´ëì¤ ì ì¸ë¬¸ì¼ë¡ ê°ì í´ëì¤ë¥¼ ë ë² ì ì¸íë©´ ì¤ë¥ê° ë°ìí©ëë¤.
class Foo {}
class Foo {} // Uncaught SyntaxError: Identifier 'Foo' has already been declared
ì´ì ì ííìì¼ë¡ ì ìí ê²½ì°ìë ì¤ë¥ê° ë°ìí©ëë¤.
var Foo = class {};
class Foo {} // Uncaught TypeError: Identifier 'Foo' has already been declared
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ì°¸ì¡°
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4