Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
JavaScript Prototype Chain Reference to Object.prototype

I need some help for understanding the prototype chain. I don't understand / not quite sure if my assumptions are correct. I want to understand the link to the Object.prototype. One example

function A(){};
var newObject=new A();

I know the newObject has an internal property [[prototype]] which has a reference to A.prototype. And this prototype-Object has also an internal property with reference to Object.prototype, right? But why does it have that reference? Is it because the prototype of A (used as constructor) is an object which can be imagined to be created by A.prototype=new Object() ( which will be done automatically in the background). And now I have a reference to the prototype of Object? I hope I explained it clearly. Please let me know your comments.

Many thanks

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Yes, your understanding is correct.

In JS, pretty much all the objects have a reference to Object.prototype in their prototype chain.

The [[Prototype]] of an object refers to Object.prototype as the end of a prototype chain. In your example, this means what you described:

            [[Prototype]]                  [[Prototype]]                   
newObject -----------------> A.prototype -----------------> Object.prototype

That applies to...

  • objects created by the Object constructor (i.e. new Object(...)),
  • those created with an object literal (which you can think of as syntax sugar for a new Object() call followed by a bunch of Object.defineProperty calls) and
  • objects created internally by the JS interpreter (like A.prototype which is created automatically when you define the A function).

There are also exceptions of this "rule" though:

  • Object.prototype itself.

    If it had a reference to... well, itself, it would create and infinite recursion when a nonexistent property is looked up. Hence, it has no prototype, which means that its [[Prototype]] is null (that's how a prototype chain "ends").

  • Custom objects created using Object.create or modified with Object.setPrototype.

    The [[Prototype]] can be set to anything this way, including null or other objects whose prototype chain doesn't end with Object.prototype.

about 4 years ago · Juan Pablo Isaza Report

0

This is indeed what the ECMAScript specification prescribes. When a function is defined with the function keyword, then an object is created from Object.prototype which is assigned to the function's prototype property, and therefor will be used as prototype for any object that is constructed by that function.

This specification can be found at Make Constructor, step 5.a:

5.a. Set prototype to OrdinaryObjectCreate(%Object.prototype%).

about 4 years ago · Juan Pablo Isaza Report

0

When it comes to javascript every value is either an object (arrays, objects, sets, maps...) or a primitive(Numbers, strings, bool ...) objects and primitives are the two data types in javascript a . You have the Number, String , Array and even Object constructors which you can use to create the corresponding value. And when you create new object using the new operator the following steps happen consecutively:

// 1. New empty object is created

// 2. the constructor function is called, and the this keyword is assigned to the empty object i.e this = {}.

// 3. the empty object is linked to the prototype of the constructor functio i.e {}.proto = constructorFunction.prototype.

// 4. the constructor function automatically return the new object {}.

keep in mind that constructorFunction.prototype is the prototype of the new object that is created from the constructorFunction and not of itself.

I hope this clears things up a little for you!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!