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

Detailed explanation of JavaScript object-oriented inheritance examples_javascript skills

WBOY
Release: 2016-05-16 15:25:29
Original
1086 people have browsed it

A simple example of object-oriented inheritance in JavaScript:
As an object-oriented language, inheritance is naturally a major feature of it. Although the object-oriented implementation mechanism of JavaScript is different from typical object-oriented ones such as C# and Java, the basic characteristics of inheritance are still there. To put it simply, To obtain the methods and attributes of the parent, here is a simple example. If you are interested, you can analyze it:

window.onload = function(){ 
 function parent(age,name){ 
  this.age = age; 
  this.name = name; 
 } 
 parent.prototype.show = function(){ 
  alert('父级方法'); 
 } 
 function child(age,name,job){ 
  parent.apply(this,arguments); 
  this.job = job; 
 } 
 (function(){ 
  for(var i in parent.prototype){ 
  child.prototype[i]=parent.prototype[i] 
 } 
 })(); 
 var b = new parent(14,'侠客行'); 
 var a = new child(15,'狼侠','侠客'); 
 a.show(); 
}
Copy after login

The above is a simple example introduction to object-oriented inheritance in JavaScript. You can study together with the previous article "Detailed explanation of object-oriented inheritance in JavaScript" , and the effect may be better.

Related labels:
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