Combining Introspection Methods
You'll learn how to use multiple introspection tools together to build a complete picture of an object's structure.
When inspecting an object, relying on a single method often gives you an incomplete view. Some properties might be non-enumerable, others might be symbols, and inherited properties add another layer. The real power comes from combining introspection methods to see the full picture.
Why Combine Methods?
Think of object introspection like examining a building. One tool shows you the front door (enumerable properties), another reveals the locked storage rooms (non-enumerable properties), and yet another uncovers the basement inherited from the original blueprint (prototype). You need all views to understand the complete structure.
Practical Combinations
To see ALL own properties:
const obj = Object.create({ inherited: 'from proto' });
obj.visible = 'enumerable';
Object.defineProperty(obj, 'hidden', { value: 'secret', enumerable: false });
obj[Symbol('id')] = 123;
const allKeys = [
...Object.getOwnPropertyNames(obj),
...Object.getOwnPropertySymbols(obj)
];
console.log(allKeys); // ['visible', 'hidden', Symbol(id)]
To distinguish own from inherited:
const allProps = Object.keys(obj); // Only enumerable own
const inherited = 'inherited' in obj && !Object.hasOwn(obj, 'inherited');
console.log(inherited); // true
To check mutability status:
const descriptors = Object.getOwnPropertyDescriptors(obj);
const isWritable = descriptors.visible.writable;
const proto = Object.getPrototypeOf(obj);
By layering Object.keys(), getOwnPropertyNames(), getOwnPropertySymbols(), and getPrototypeOf(), you can navigate any object's complete structure, understanding both what's visible and what's hidden beneath the surface.
Key Takeaway: No single introspection method reveals everything—combine Object.keys(), getOwnPropertyNames(), getOwnPropertySymbols(), descriptors, and prototype checks to fully understand an object's structure.