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.
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 fromObject.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()orMath.floor(2.5)). - All function objects also have an internal
[[Construct]]method if they’re designed to be used as constructors (likenew Array()), though some built-in functions (such asparseInt()) don’t implement this—trying to usenew parseInt()will throw aTypeError.
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
nullis 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 doArray(3)ornew Array(3)) and[[Construct]]methods. - Method-attached functions: Methods like
Math.sqrt()orJSON.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 (likeMath.PI) and methods (likeMath.cos())JSON: Handles JSON serialization and deserialization (JSON.stringify(),JSON.parse())Reflect: Provides methods for interceptable JavaScript operations (likeReflect.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 likepush(),map()that all array instances inheritString.prototype: HastoLowerCase(),slice()—string primitives get temporarily wrapped intoStringobjects to access these methods automatically.
Quick Example to Connect the Dots
Let’s use Array to tie everything together:
Arrayitself 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 arrayArray.prototypeis a regular object that’s the prototype ofarr1andarr2. When you callarr1.push(5), you’re actually invoking thepushmethod fromArray.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 aStringobject (a built-in object) to access the method fromString.prototype, then discards the wrapper. - Not all built-in functions are constructors: For example,
Math.floor()is a function object but lacks[[Construct]]—trynew Math.floor()and you’ll get aTypeError.
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

