GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing id.javascript.info — Mewarisi dari SyntaxError

  • Tutorial
  • Bahasa JavaScript
  • Penanganan kesalahan
  • Kesalahan khusus, memperluas Kesalahan
kembali ke pelajaran

Mewarisi dari SyntaxError

pentingnya: 5

Buat kelas FormatError yang diwarisi dari bawaan kelas SyntaxError.

Ini harus mendukung properti message, name dan stack.

Contoh penggunaan:

let err = new FormatError('formatting error');

alert(err.message); // formatting error
alert(err.name); // FormatError
alert(err.stack); // stack

alert(err instanceof FormatError); // true
alert(err instanceof SyntaxError); // true (karena mewarisi dari SyntaxError)
class FormatError extends SyntaxError {
  constructor(message) {
    super(message);
    this.name = this.constructor.name;
  }
}

let err = new FormatError("formatting error");

alert( err.message ); // formatting error
alert( err.name ); // FormatError
alert( err.stack ); // stack

alert( err instanceof SyntaxError ); // true
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.