3

In JavaScript, when I define a new function

function Foo () { /* code */ }

The prototype of this function is set to a new object and that object's constructor is set to the newly created function itself, so

Foo.prototype.constructor === Foo

This behaviour is well-described both in the ECMAScript spec and also on a more human-friendly MDN.

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

For example, if I were to

delete Object.prototype.constructor

(which I can, because, at least in Node.js, the property is defined as writable and configurable), am I somehow affecting the language's functionality?

After some rudimentary tests it does not seem to affect defining creating new objects as the property is defined properly for each new function / object I create.

Note: I am aware that this could break 3rd party code - I am only interested in the core language's functionality.

Robert Rossmann
  • 11,931
  • 4
  • 42
  • 73
  • See http://stackoverflow.com/questions/4012998/what-it-the-significance-of-the-javascript-constructor-property – cli_hlt Apr 27 '15 at 08:35

0 Answers0