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

JavaScript标准内置对象是否均为构造函数?

Hey there! It sounds like you’re digging into the nitty-gritty of JavaScript’s core, which is awesome—those underlying principles can definitely feel tricky even after months of learning. Let’s break down Standard Built-In Objects (SBIOs) starting from what you already know to fill in those gaps.

Understanding JavaScript Standard Built-In Objects

First, Let’s Tie This to What You Already Know

You’re right on the money with these foundational points:

  • All functions (both built-in and user-defined) are function objects—they inherit from Function.prototype, which itself inherits from Object.prototype.
  • The critical difference between a regular object and a function object is the internal [[Call]] method: this is what lets you invoke the function with parentheses (e.g., myCustomFunc() or Math.floor(2.5)).
  • All function objects also have an internal [[Construct]] method if they’re designed to be used as constructors (like new Array()), though some built-in functions (such as parseInt()) don’t implement this—trying to use new parseInt() will throw a TypeError.

What Are Standard Built-In Objects, Exactly?

SBIOs are the pre-defined objects that come with every JavaScript environment (browser, Node.js, etc.). They’re grouped into categories based on their role, which makes them easier to wrap your head around:

1. Value Properties (Non-Object Primitives)

These aren’t objects at all—they’re primitive values exposed as global properties:

  • Infinity, NaN, undefined
  • Note: While null is a primitive, it’s a language keyword rather than an SBIO property.

2. Function Objects (Callable Built-Ins)

These are function objects you can invoke directly (some can also be used as constructors):

  • Utility functions: parseInt(), parseFloat(), isNaN()
  • Constructor functions: Array(), Object(), Date()—these have both [[Call]] (so you can do Array(3) or new Array(3)) and [[Construct]] methods.
  • Method-attached functions: Methods like Math.sqrt() or JSON.parse() are function objects attached to regular SBIOs (we’ll cover those next).

3. Regular Object SBIOs (Non-Callable)

These are plain objects that hold related methods and properties, but you can’t invoke them directly (they don’t have the [[Call]] internal method):

  • Math: A collection of mathematical constants (like Math.PI) and methods (like Math.cos())
  • JSON: Handles JSON serialization and deserialization (JSON.stringify(), JSON.parse())
  • Reflect: Provides methods for interceptable JavaScript operations (like Reflect.get(), Reflect.set())

4. Prototype Objects

Every built-in constructor has a prototype object that defines methods for all instances created with that constructor:

  • Array.prototype: Has methods like push(), map() that all array instances inherit
  • String.prototype: Has toLowerCase(), slice()—string primitives get temporarily wrapped into String objects to access these methods automatically.

Quick Example to Connect the Dots

Let’s use Array to tie everything together:

  • Array itself is a function object with both [[Call]] and [[Construct]]:
    const arr1 = Array(2); // Uses [[Call]] to create an array with 2 empty slots
    const arr2 = new Array(2); // Uses [[Construct]] to create the same array
    
  • Array.prototype is a regular object that’s the prototype of arr1 and arr2. When you call arr1.push(5), you’re actually invoking the push method from Array.prototype—that’s prototype inheritance in action.

Common Confusion Points to Clarify

  • Primitive wrappers: When you do "hello".toUpperCase(), JavaScript temporarily wraps the string primitive into a String object (a built-in object) to access the method from String.prototype, then discards the wrapper.
  • Not all built-in functions are constructors: For example, Math.floor() is a function object but lacks [[Construct]]—try new Math.floor() and you’ll get a TypeError.

It’s totally normal to feel stuck on these low-level details—they’re what separate casual JS users from folks who really understand how the language ticks. Keep testing edge cases and poking at examples, and it’ll click over time!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:29:12