JS Reflexion: see what is inside the object

Sometimes, our code can get very complex because objects might extend the other objects. So it can get very tricky to debug the code. That’s why JS has useful feature called Reflection, which allows us to see what is inside the object.

The above code will sorta extend the john object with user object.  If you run the code below

So, what happens is, JS compiler will go through the Prototype chain, by finding firstname and lastname from John object, then getFullName() from it’s parent object which is Person. Basically, prototype chaining is feature of JS that automatically will search for the Objects fields and methods, if it cannot find it, JS will ascend to it’s parent. Js will continue searching for Objects fields and methods all the way till the Object.  All primitives, funcitons and objects in JS are extended from the Object object.


Below code, shows only the content of the john object



Leave a Reply

Your email address will not be published. Required fields are marked *