If an object wants to call a method in another object

First understand: Everything is an object
Method 1:
The prototype pointer ( proto ) of the object points to the object you want to call
Insert picture description here
Method 2: Use setPrototypeOf() to make the pointer of o point to the proto
Insert picture description hereMethod 3: Inherit
1. Person.prototype = new Animal( )
The prototype of the child constructor is an instance of the parent constructor. Instances can call the methods in the prototype, so the prototype of the child constructor can call the methods in the parent constructor prototype, and the instance of the child constructor can also call the methods in the parent constructor prototype
2.Person.prototype. proto = Animal. The prototype of the
child constructor points to the prototype of the parent constructor

Guess you like

Origin blog.csdn.net/weixin_49549509/article/details/108182435