Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the advantages and disadvantages of the js prototype chain?

Shulou Source: shulou.com Published: 2022-06-03 07:35:22 11月15日 Update

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.

Tags: Prototypes examples methods problems advantages and disadvantages subclasses more help answers easy easy advantages content literal objects guys partners attributes knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info macOS Docker NVidia