TypeError: More arguments needed

JavaScript 異常“需要更多引數”發生在函式呼叫方式錯誤時。需要提供更多引數。

訊息

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)

錯誤型別

TypeError.

哪裡出錯了?

函式呼叫方式存在錯誤。需要提供更多引數。

示例

未提供所需引數

Object.create() 方法至少需要一個引數,Object.setPrototypeOf() 方法至少需要兩個引數

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

你可以透過將 null 設定為原型來解決此問題,例如

js
const obj = Object.create(null);

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

另見