Get the prototype of an object with Reflect.getPrototypeOf method

In this example we will retrieve the value of the __proto__ property of an object with the Reflect.getPrototypeOf method so we can access it later on. This method is the same as the Object.getPrototypeOf method and both have been introduced in the ECMAScript6.

var obj1 = {
		__proto__ : {
			name : "Johnny",
			salary : 3000,
			job : "programmer"

var obj2 = Reflect.getPrototypeOf(obj1);

console.log( + " is a " + obj2.job + " with monthly salary of " + obj2.salary);

The outcome is as follow:

Johnny is a programmer with monthly salary of 3000

Leave a Reply

Be the First to Comment!

Notify of