在JavaScript中显示Node对象:为何Object.Node返回undefined?
Object.Node is undefined but Node works directly? Great question! Let’s break this down clearly:
Nodeis a global DOM interface, not a property of theObjectconstructor. In browsers, all built-in DOM interfaces (likeNode,Element,Document) live on the globalwindowobject. When you writeconsole.log(Node)directly, you’re actually accessingwindow.Nodeunder the hood—this works because it’s part of the browser’s DOM API.Objectis a separate built-in constructor focused on JavaScript object operations. It has its own static properties and methods (likeObject.keys(),Object.assign(), orObject.prototype), but it doesn’t include DOM-related interfaces as direct properties. WhileNodedoes inherit fromObject.prototype(since nearly everything in JS is an object at its core), that prototype chain relationship doesn’t meanNodeis stored as a property of theObjectfunction itself.
To confirm this, try running these lines in your browser console:
console.log(window.Node); // Same result as just `Node`—it exists! console.log(Object.hasOwnProperty('Node')); // Returns false—Object has no such property
Think of it like this: Object is a toolbox for working with plain JS objects, while Node is a separate tool for interacting with DOM nodes. They’re both available in the global "workshop" (the window object), but one isn’t stored inside the other.
内容的提问来源于stack exchange,提问作者Sami Kh

