What does 'Object' refer to when calling JS native object methods?
In the code below, I was trying to figure out what ‘this’ refers to in line 3. Looking at what the last line logs, I can deduce that ‘this’ refers to objInstance.
My reasoning entails using the ‘left to the dot’ rule, so ‘this’ on line 3 should refer to what is at the left of the getPrototypeOf method, which is ‘Object’.
The question is, I am not sure if ‘Object’ actually refers to objInstance. This is because according to my logic, objInstance must have a property called getPrototypeOf (and getOwnPropertyNames) in its dunder proto, but it does not when I log in the console.
Am I correct on how I concluded that ‘this’ refers to objInstance regardless? If not, what am I missing?
class Example { constructor () { const proto = Object.getPrototypeOf(this); console.log(Object.getOwnPropertyNames(proto)); } first() {} second() {} static third() {} } const objInstance = new Example(); //logs ['constructor', 'first', 'second']