Prototype of Javascript object

  • 2020-03-30 02:52:17
  • OfStack

Every object in Javascript has a prototype. Try it on:
var Richard = new Object(); 

The result is depressing. The browser pops up with undefined...

What's going on?

Here's another example:
function Richard(){} 

The above example seems to show that only a function Object has a prototype, while the average Object has no prototype. What's the truth?

Let's do one more sentence:
var Richard = new Object(); 

Does that make sense?

A common misconception is that prototype, the prototype chain that forms the Javascript object, is a property called prototype and is accessible. In fact, Javascript's prototype and the property called prototype had nothing to do with each other at first, just two different things.

For general objects, we can only access prototype which is inherited from the Object Object by using properties like s/s s/s.

For a Function object, the prototype property of the Function object is assigned to the prototype property when it is created.

Related articles: