While learning prototypical inheritance, I have seen the prototype referring to Array, Object or empty Function.
I am new to JavaScript programming (prototypical inheritance world) and when debugging SAPUI5 framework I have noticed the prototype is pointing to a constructor.
Could you please explain me in which scenario [[Prototype]]
points to a constructor. Can [[Prototype]]
point to any other apart from these 4 ( Array, Object, Empty Function and Constructor )?
More Info:
If the function is a constructor function it should have a prototype property at the same level where it displays the [[Prototype]]
Constructor Function Example with prototype property and [[Prototype]]
A [[prototype]] can point to any object (or null
). What you're asking though is how that object is displayed in the devtools - see How does DevTools determine an object's constructor's name? and Javascript Debugging in Chrome - object name? - which uses the name of the function that constructed the object. It means that the prototype is an object or an array or a function, not actually the global Object
/Array
/Function
. When you define your own classes, it'll be the name of that class, which can be anything. In your exampe, SAPUI5 appears to have defined its class(es) via function constructor() {}
, which is unusual but doesn't matter.