If you want to implement object A to inherit B, and B to inherit C, is there any other way to implement it besides assigning the instance of B to the prototype of A, and assigning the instance of C to the prototype of B? I am a beginner and have not found any relevant information. Please give me some advice
In other words, can your question be understood as: "In addition to prototypal inheritance, what other inheritance methods does JavaScript have?" If so, the answer is no, because JavaScript inheritance is implemented based on the prototype chain mechanism.
If you are asking about how to write prototypal inheritance, there are several ways:
1) new constructor creation; (that is, the one mentioned in the question)
2) Object.create;
1) Object literal;
Specific usage , there is a lot of information:
https://developer.mozilla.org...
In addition to prototypal inheritance, there are also APIs provided by js: call and applyChange the pointer of this and borrow methods
call usage:
apply Usage:
The difference between the two is that the former passes parameters one by one, while the latter passes parameters by passing an array and then spreading it out
There are other uses for these two, such as converting pseudo arrays into real arrays:
Object.prototype.tostring.call (pseudo array)