Baseline Widely available
extends
í¤ìëë í´ëì¤ë¥¼ ë¤ë¥¸ í´ëì¤ì ììì¼ë¡ ë§ë¤ê¸° ìí´ class ì ì¸ ëë class ìì ì¬ì©ë©ëë¤.
class DateFormatter extends Date {
getFormattedDate() {
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
return `${this.getDate()}-${months[this.getMonth()]}-${this.getFullYear()}`;
}
}
console.log(new DateFormatter("August 19, 1975 23:15:30").getFormattedDate());
// Expected output: "19-Aug-1975"
구문
class ChildClass extends ParentClass { ... }ì¤ëª
extends
í¤ìëë ë´ì¥ ê°ì²´ë¿ë§ ìëë¼ ì¬ì©ì ì ì í´ëì¤ë¥¼ íì í´ëì¤ë¡ ë§ë¤ê¸° ìí´ ì¬ì©ë ì ììµëë¤.
íì¥( í´ëì¤)ì .prototype
ì Object
ëë null
ì´ì´ì¼ í©ëë¤.
extends
ì¬ì©í기
첫 ë²ì§¸ ìë Polygon
í´ëì¤ë¡ë¶í° Square
í´ëì¤ë¥¼ ë§ëëë¤. ì´ ìë live demo (source)ìì ë°ì·íìµëë¤.
class Square extends Polygon {
constructor(length) {
// ì¬ê¸°ì, lengthì í¨ê» ë¶ëª¨ í´ëì¤ì ìì±ì를 í¸ì¶
// Polygonì ëë¹ ë° ëì´ê° ì ê³µë¨
super(length, length);
// 주ì: íì í´ëì¤ìì, super()ê° ë¨¼ì í¸ì¶ëì´ì¼ 'this'를
// ì¬ì©í ì ììµëë¤. ì´ë¥¼ 빼먹ì¼ë©´ 참조 ì¤ë¥ê° ë°ìí©ëë¤.
this.name = "Square";
}
get area() {
return this.height * this.width;
}
set area(value) {
this.area = value;
}
}
ë´ì¥ ê°ì²´ì extends
ì¬ì©í기
ì´ ìì ë ë´ì¥ ê°ì²´ Date
를 íì¥í©ëë¤. ì´ ìì ë live demo (source)ìì ë°ì·íìµëë¤.
class myDate extends Date {
constructor() {
super();
}
getFormattedDate() {
var months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
return (
this.getDate() + "-" + months[this.getMonth()] + "-" + this.getFullYear()
);
}
}
null
íì¥
null
ìì íì¥ì prototype ê°ì²´ê° Object.prototype
ì¼ë¡ë¶í° ììë°ì§ ìì ê²ì ì ì¸íë©´ ë³´íµ í´ëì¤ì²ë¼ ëìí©ëë¤.
class nullExtends extends null {
constructor() {}
}
Object.getPrototypeOf(nullExtends); // Function.prototype
Object.getPrototypeOf(nullExtends.prototype); // null
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ì°¸ì¡°
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