In this answer, I instructed the questioner not to overwrite the native Object function in Javascript, because I thought that it would mess up the object creation process.
But then, I thought about it, and figured that it’s pretty unlikely that all objects are actually created using this function, along with the new keyword.
For example, is it used when objects are created with a literal notation (var a = {...})? Or does it simply do this = {}? Is it possible to actually assign values to this at all?
I saw this question, that is similar, and apparently Object behaves differently when used without the new keyword… How is the function actually implemented?
You can overwrite Object in Chrome/V8 and bad things happen if you do. Typing the following gets these responses.
Looking at Number.prototype we can see a full set of methods and Object as Number’s prototype:
But if we overwrite Object
Number’s prototype goes a bit wonky:
As Object is the root of the hierarchy there’s a bit of a paradox if you reassign it to another object.