1
第二行顯示錯誤。爲什麼這段代碼顯示錯誤?
"ReferenceError: specialTrick is not defined
at CoolGuy.showoff (<anonymous>:23:40)
at <anonymous>:31:5
at Object.InjectedScript._evaluateOn (<anonymous>:875:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:808:34)
at Object.InjectedScript.evaluate (<anonymous>:664:21)"
class CoolGuy {
specialTrick = null;
CoolGuy(trick) {
specialTrick = trick
}
showOff() {
console.log("Here's my trick: ", specialTrick);
}
}
Joe = new CoolGuy("rope climbing");
Joe.shoeOff();
也許你應該定義specialTrick – user2182349
也許嘗試'VAR specialTrick'(或'讓specialTrick'在ES6) –
https://webkit.org/blog/1544/web-inspector-understanding-stack-traces/ – Isaac