Detaching <Object> .prototype.constructor

In JavaScript, when I define a new function

function Foo () { /* code */ }

      

The prototype of this function is assigned to a new object, and the object is constructor

set to the newly created function, so

Foo.prototype.constructor === Foo

      

This behavior is well documented in both the ECMAScript specification and the more user-friendly MDN .

Is this property used in any other way than just a friendly shortcut to access the constructor function?

For example, if I were

delete Object.prototype.constructor

      

(which I can, since at least in Node.js the property is defined to be writable and configurable ), I somehow affect the functionality of the language

After some rudimentary tests, this does not affect the definition of creating new objects as the property is defined correctly for every new function / object that I create.

Note. I know this might break third party code - I'm only interested in the functionality of the main language.

+3
javascript node.js prototype


source to share


No one has answered this question yet

See similar questions:

115
What is the value of the Javascript constructor property?

or similar:

5722
How can I remove a property from a JavaScript object?
5101
What's the most efficient way to deeply clone an object in JavaScript?
3714
How to check if an array contains a value in JavaScript?
2886
How do I clone a JavaScript object correctly?
2709
Detecting object property undefined
2685
Checking if a key exists in a JavaScript object?
2543
How can I check if an object is an array?
2466
Sorting an array of objects by the value of the string property
2350
Storing objects in HTML5 localStorage
297
Understanding the difference between Object.create () and the new SomeFunction ()



All Articles
Loading...
X
Show
Funny
Dev
Pics