TypeError: More arguments needed

Ngoại lệ JavaScript "more arguments needed" xảy ra khi có lỗi trong cách gọi hàm. Cần cung cấp thêm đối số.

Thông báo

TypeError: Object prototype may only be an Object or null: undefined (V8-based)
TypeError: Object.create requires at least 1 argument, but only 0 were passed (Firefox)
TypeError: Object.setPrototypeOf requires at least 2 arguments, but only 0 were passed (Firefox)
TypeError: Object.defineProperties requires at least 1 argument, but only 0 were passed (Firefox)
TypeError: Object prototype may only be an Object or null. (Safari)

Loại lỗi

TypeError.

Nguyên nhân?

Có lỗi trong cách gọi hàm. Cần cung cấp thêm đối số.

Ví dụ

Thiếu đối số bắt buộc

Phương thức Object.create() yêu cầu ít nhất một đối số và phương thức Object.setPrototypeOf() yêu cầu ít nhất hai đối số:

js
const obj = Object.create();
// TypeError: Object.create requires at least 1 argument, but only 0 were passed

const obj2 = Object.setPrototypeOf({});
// TypeError: Object.setPrototypeOf requires at least 2 arguments, but only 1 were passed

Bạn có thể khắc phục bằng cách đặt null làm prototype, ví dụ:

js
const obj = Object.create(null);

const obj2 = Object.setPrototypeOf({}, null);

Xem thêm