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
çåé¡å¥ãæ¤ç¯ä¾æåèªç·ä¸ç¤ºä¾ã
class Square extends Polygon {
constructor(length) {
// Here, it calls the parent class' constructor with lengths
// provided for the Polygon's width and height
super(length, length);
// Note: In derived classes, super() must be called before you
// can use 'this'. Leaving this out will cause a reference error.
this.name = "Square";
}
get area() {
return this.height * this.width;
}
}
ä½¿ç¨ extends
æ¼å
§å»ºé¡å¥
éåç¯ä¾æ´å±äºå
§å»ºç Date
é¡å¥ãæ¤ç¯ä¾æåèªç·ä¸ç¯ä¾ã
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
ï¼ä½æ°å°è±¡çååä¸æç¹¼æ¿ Object.prototype
ã
class nullExtends extends null {
constructor() {}
}
Object.getPrototypeOf(nullExtends); // Function.prototype
Object.getPrototypeOf(nullExtends.prototype); // null
new nullExtends(); //ReferenceError: this is not defined
æ¨æº ç覽å¨ç¸å®¹æ§ åè¦
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