Skip to content
Advertisement

How to visualize JavaScript wrapper objects?

Lately I read that for every primitive data type, a wrapper object is created. It is this wrapper object what makes it possible to use methods with that data, and that makes sense.

I also read that functions are objects. I found out that I can visualize the function-as-an-object through console.dir().

However, when I apply console.dir() to a primitive data type, I get the value of the variable. But I was expecting to get an object, just as with functions. Is this because they are different cases? How can I access the wrapper object of a primitive data type?

Advertisement

Answer

try __proto__ property. eg var a = ‘something’; console.log(a.__proto__); this is a deprecated feature though, the better way would be to use Object.getPrototypeOf(<primitive here>). take a look at this for more info about prototypes in js

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement