Home > Web Front-end > JS Tutorial > body text

Detailed explanation of object-oriented inheritance in JS

小云云
Release: 2018-03-16 17:07:15
Original
1113 people have browsed it

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这个构造函数
Copy after login

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

Detailed explanation of the usage of PHP object-oriented inheritance (optimization and reduce code duplication)

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!