What are the advantages and disadvantages of the js prototype chain?
What are the advantages and disadvantages of the js prototype chain? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
1, the advantage is very pure inheritance relationship, the instance is the instance of the subclass, but also the instance of the parent class. The subclass can access the new prototype methods and properties of the parent class.
2. The disadvantage is that the method needs to be rewritten after replacing the prototype. You cannot create a prototype method with object literals.
Unable to implement multiple inheritance. All instances share reference types.
Example
Function Person () {} Person.prototype.name = 'Jason';Person.prototype.getYear = function () {return 1989;} let person = new Person () Console.log (person.__proto__ = Person.prototype) / / true's questions on what are the advantages and disadvantages of the js prototype chain are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.