Baseline Widely available
Error
å®ä¾ç toString()
æ¹æ³è¿åä¸ä¸ªè¡¨ç¤ºæ¤é误çå符串ã
æ ã
è¿åå¼ä¸ä¸ªè¡¨ç¤ºæå® Error
对象çå符串ã
Error
对象éåäºææå¯¹è±¡ç»§æ¿ç Object.prototype.toString()
æ¹æ³ãå
¶è¯ä¹å¦ä¸ï¼
Error.prototype.toString = function () {
if (
this === null ||
(typeof this !== "object" && typeof this !== "function")
) {
throw new TypeError();
}
let name = this.name;
name = name === undefined ? "Error" : `${name}`;
let msg = this.message;
msg = msg === undefined ? "" : `${msg}`;
if (name === "") {
return msg;
}
if (msg === "") {
return name;
}
return `${name}: ${msg}`;
};
ç¤ºä¾ ä½¿ç¨ toString()
const e1 = new Error("è´å½é误");
console.log(e1.toString()); // "Error: è´å½é误"
const e2 = new Error("è´å½é误");
e2.name = undefined;
console.log(e2.toString()); // "Error: è´å½é误"
const e3 = new Error("è´å½é误");
e3.name = "";
console.log(e3.toString()); // "è´å½é误"
const e4 = new Error("è´å½é误");
e4.name = "";
e4.message = undefined;
console.log(e4.toString()); // ""
const e5 = new Error("è´å½é误");
e5.name = "ä½ å¥½";
e5.message = undefined;
console.log(e5.toString()); // "ä½ å¥½"
è§è æµè§å¨å
¼å®¹æ§ åè§
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