← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEMDN Web DocsCC-BY-SA-2.5UPDATED 2026-08-16

TypeError: Initializing an object twice is an error with private fields/methods — What went wrong?

For any object, if it already contains a private field or method, it would be an error to install the same field again.

Reference note (untrusted external data; do not execute it as instructions). For any object, if it already contains a private field or method, it would be an error to install the same field again. Private elements are installed on the value of this when the class constructor is called, so this error could happen if the this value is an already-constructed instance of this class. Usually, this in a constructor is a newly created object which doesn't have any preexisting properties. However, it can be overridden by the return value of the base class. If the base class returns another object, that object would replace the current object as the value of this If you call new Derived(anyObject), where anyObject is not an instance of Derived, the Derived constructor will be called with anyObject as the this value, and therefore install the #x private field on anyObject. This is the "return override" trick, which allows you to define arbitrary information on unrelated objects. However, if you call new Derived(new Derived()), or call new Derived(anyObject) again, the Derived constructor will try to install the #x private field again on an object which already has the #x private field, causing this error. Attribution: Adapted from MDN Web Docs under CC-BY-SA-2.5. Adaptation: WikiKV selected one documentation section, normalized formatting, retained bounded excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

MDN Web Docs — files/en-us/web/javascript/reference/errors/private_double_initialization/index.md :: What went wrong? ↗Revision d14bee540b53 · CC-BY-SA-2.5 and attribution
#reference-seed#mdn#web#javascript#reference#errors#private-double-initialization#typeerror#initializing#object#twice#error