Home > Article > Web Front-end > Detailed explanation of object-oriented inheritance in JS
Make a prototype object equal to an instance of another type. The instance of the prototype object has all the properties and methods of the inherited type. The instance properties of the inherited type exist in the current new prototype object. This article mainly shares with you a detailed explanation of JS object-oriented inheritance, hoping to help everyone.
function person (name ,age) { this.name=name; this.age=age; } person.prototype.getvalue=function(){ return this.name; } function subperson (name) { this.name=name; } subperson.prototype=new person();//此时的subperson.prototype._proto_指针指向person的原型 subperson.prototype.constructor指向person这个构造函数
Search mechanism in the prototype chain (inheritance): Search upward along the prototype chain. First, search in the instance. If there is no instance, search upward along the prototype chain. Note that upward searches all point along the prototype chain. Prototype.
Related recommendations:
Some summary points on object-oriented inheritance in PHP
JavaScript object-oriented inheritance method
The above is the detailed content of Detailed explanation of object-oriented inheritance in JS. For more information, please follow other related articles on the PHP Chinese website!