Detailed JavaScript _javascript techniques based on object-oriented inheritance instances

Source: Internet
Author: User

A simple example of JavaScript object-oriented inheritance:
As an object-oriented language, inheriting nature is one of its great features, although JavaScript's object-oriented implementation mechanism is different from the typical object-oriented objects of C # and Java, but the basic feature of inheritance is to get the methods and properties of the parent, which is a simple example. We are interested to analyze:

Window.onload = function () { 
 function parent (age,name) { 
  this.age = age; 
  this.name = name; 
 Parent.prototype.show = function () { 
  alert (' parent method '); 
 } 
 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, ' Knight's Line '); 
 var a = new Child (15, ' Werewolf ', ' Knight '); 
 A.show (); 
}

The above is a simple example of JavaScript object-oriented inheritance, you can combine the previous "detailed JavaScript based on object-oriented inheritance" to study together, may be better results.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.