有什么方法可以覆寫我的 RunTimeError 類中 asString 函式的內容,因為我需要錯誤訊息與我的通用 Error 類中的錯誤訊息不同
class Error {
errorName: string;
details: string;
posStart: Position;
posEnd: Position;
constructor({errorName, details, posStart, posEnd}: ErrorTypes) {
this.errorName = errorName
this.details = details
this.posStart = posStart
this.posEnd = posEnd
}
asString() {
let result: string = `${this.errorName} on line ${this.posStart.ln 1}: ${this.details}`
return result
}
}
class RunTimeError extends Error {
context: any
constructor({details, posStart, posEnd, context}: SubErrorTypes) {
super({errorName:"Runtime Error", details:details, posStart:posStart, posEnd:posEnd})
this.context = context
}
//change contents of asString
}
uj5u.com熱心網友回復:
將道具傳遞給通用類函式 asString
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/489679.html
上一篇:Java子類用超類的引數初始化
