EvalError
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
Đối tượng EvalError chỉ ra một lỗi liên quan đến hàm toàn cục eval(). Ngoại lệ này không còn được JavaScript ném ra nữa, tuy nhiên đối tượng EvalError vẫn được giữ lại để tương thích.
EvalError là một serializable object, vì vậy nó có thể được nhân bản với structuredClone() hoặc sao chép giữa các Worker bằng cách sử dụng postMessage().
EvalError là lớp con của Error.
Constructor
EvalError()-
Tạo một đối tượng
EvalErrormới.
Thuộc tính instance
Cũng kế thừa các thuộc tính instance từ lớp cha Error.
Các thuộc tính này được định nghĩa trên EvalError.prototype và được chia sẻ bởi tất cả các instance EvalError.
EvalError.prototype.constructor-
Hàm constructor đã tạo ra đối tượng instance. Đối với các instance
EvalError, giá trị khởi tạo là constructorEvalError. EvalError.prototype.name-
Đại diện cho tên của loại lỗi. Đối với
EvalError.prototype.name, giá trị khởi tạo là"EvalError".
Phương thức instance
Kế thừa các phương thức instance từ lớp cha Error.
Ví dụ
>Tạo một EvalError
try {
throw new EvalError("Hello");
} catch (e) {
console.log(e instanceof EvalError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "EvalError"
console.log(e.stack); // Stack of the error
}
Đặc tả kỹ thuật
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-native-error-types-used-in-this-standard-evalerror> |