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

JavaScript中Object.prototype的层级是什么?及代码输出解析请求

Hey there! Let's tackle your JavaScript questions step by step, nice and clear.

1. The Hierarchy of Object.prototype in JavaScript

In JavaScript, Object.prototype sits at the very top of the prototype chain for almost all objects—with the only exception being null. Here's how the hierarchy breaks down:

  • Plain objects (like const obj = {}) have their __proto__ pointing directly to Object.prototype.
  • Function objects (including built-in constructors like Object, Array, or your custom functions) first inherit from Function.prototype, and then Function.prototype's __proto__ points to Object.prototype.
  • Finally, Object.prototype.__proto__ is null—this is the end of the prototype chain; there's nothing above it to inherit from.

To visualize it simply:

Your Custom Object → Object.prototype → null
Object (the constructor function) → Function.prototype → Object.prototype → null
2. Breaking Down Your Code's Output

Let's go through each log statement and why it outputs what it does:

First log: console.log(Object);

Object is a built-in constructor function provided by JavaScript. When you log it directly, you see ƒ Object() { [native code] }—this is just the browser/engine's way of showing you that this is a native (engine-implemented) function, not one written in JavaScript itself.

Second log: console.log(Object.__proto__);

Remember, Object is a function, not a plain object. All functions in JavaScript inherit from Function.prototype. When you log Object.__proto__, you're seeing Function.prototype itself, which is represented as ƒ () { [native code] }—it's a special empty function that serves as the prototype for all function objects.

Third log: console.log(obj.prototype);

Here's the key point: only function objects have a prototype property. The variable obj is a plain object (created with {}), so it doesn't have a prototype attribute at all. That's why this log outputs undefined.

Quick note to avoid confusion: Every object (including functions) has a __proto__ property (or you should use Object.getPrototypeOf() for better practice) that points to its prototype. The prototype property is exclusive to functions, and it's what gets assigned as the __proto__ of any instances created with that function via new.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 09:21:37