Baseline Widely available
class ííìì ECMAScript 2015 (ES6)ìì í´ëì¤ë¥¼ ì ìíë í ë°©ë²ì ëë¤. function ìê³¼ ë¹ì·íê², class ìì ê¸°ëª (named) ëë ìµëª (unnamed)ì¼ ì ììµëë¤. ê¸°ëª ì¸ ê²½ì°, í´ëì¤ëª ì í´ëì¤ ë³¸ì²´(body)ììë§ ì§ì(local)ì ëë¤. JavaScript í´ëì¤ë íë¡í íì (ìí) ê¸°ë° ììì ì¬ì©í©ëë¤.
ìëí´ ë³´ê¸°const Rectangle = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
area() {
return this.height * this.width;
}
};
console.log(new Rectangle(5, 8).area());
// Expected output: 40
구문
var MyClass = class [className] [extends] {
// class body
};
ì¤ëª
class ìì class 문과 êµ¬ë¬¸ì´ ë¹ì·í©ëë¤. ê·¸ë¬ë, class ìì ê²½ì° í´ëì¤ëª ("binding identifier")ì ìëµí ì ìëë° class 문ì¼ë¡ë í ì ììµëë¤.
class 문과 ê°ì´, class ìì 본체ë ì격 모ëìì ì¤íë©ëë¤.
ìì ê°ë¨í class ìì´ê² ë°ë¡ ë³ì "Foo"를 ì¬ì©íì¬ ì°¸ì¡°í ì ìë ê°ë¨í ìµëª class ìì ëë¤.
var Foo = class {
constructor() {}
bar() {
return "Hello World!";
}
};
var instance = new Foo();
instance.bar(); // "Hello World!"
Foo.name; // ""
Named class ì
ë¹ì ì´ í´ëì¤ ëª¸íµ ë´ìì íì¬ í´ëì¤ë¥¼ 참조íê³ ì¶ë¤ë©´, ì ëª class ìì ë§ë¤ ì ììµëë¤. ì´ ì´ë¦ì ì¤ì§ class ì ìì²´ ë²ìììë§ ë³¼ ì ììµëë¤.
var Foo = class NamedFoo {
constructor() {}
whoIsThere() {
return NamedFoo.name;
}
};
var bar = new Foo();
bar.whoIsThere(); // "NamedFoo"
NamedFoo.name; // ReferenceError: NamedFooê° ì ìëì§ ìì
Foo.name; // "NamedFoo"
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
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