You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建新对象时:为何选用Object.create(Object.prototype)而非Object.create(Object)

Great question! Let's unpack the difference between these two lines of code step by step—once you see what each does under the hood, you'll immediately get why Object.create(Object.prototype) is the right pick for creating a plain, standard object.

First, let's recall what Object.create() does: it creates a new object, and sets the first argument as the prototype of that new object. So the key here is understanding what Object vs Object.prototype actually is.

What is Object?

Object is a built-in constructor function in JavaScript. Yes, it's a function—not just a plain object. Its own prototype is Function.prototype (since all functions inherit from that), and it has properties like name (set to "Object"), length (set to 1, because the Object constructor expects one argument), plus all the methods from Function.prototype like call(), apply(), bind().

What is Object.prototype?

Object.prototype is the top of the prototype chain for all plain JavaScript objects. It's where methods like toString(), hasOwnProperty(), valueOf() live—these are the methods we expect every regular object to have.


Let's look at var task = Object.create(Object)

When you do this, you're setting the prototype of task to the Object constructor function. That means:

  • task will inherit all properties/methods from Object (the function) and Function.prototype.
  • If you check task instanceof Function, it will return true—because Function.prototype is in its prototype chain. That's weird if you just wanted a plain data object!
  • You'll have access to function-specific methods like task.call() or task.bind() on your "object", which you almost never need for a regular object.

Now var task = Object.create(Object.prototype)

This is what you want for a standard plain object:

  • The prototype of task is Object.prototype, so it inherits all the standard object methods (toString, hasOwnProperty, etc.)—just like an object created with {} (the object literal syntax).
  • task instanceof Object returns true (as expected), and task instanceof Function returns false—which is exactly what we want for a regular data object.
  • This object has no extra function-related baggage; it's a clean, standard object ready to hold your data.

A quick example to see the difference

const task1 = Object.create(Object);
console.log(task1 instanceof Function); // true (unexpected!)
console.log(task1.name); // "Object" (inherited from the Object constructor)

const task2 = Object.create(Object.prototype);
console.log(task2 instanceof Function); // false (correct!)
console.log(task2.name); // undefined (no inherited name property)

Wrap-up

Use Object.create(Object.prototype) when you want a plain object with the standard prototype chain. Using Object.create(Object) creates an object that inherits from a function, which is almost never what you intend when creating a regular data object—it adds unnecessary function-related properties and behavior that can lead to confusion or bugs.

内容的提问来源于stack exchange,提问作者Bikash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:26:08