Object-oriented inheritance instance (a how to inherit b problem) (write from)

Source: Internet
Author: User
Tags inheritance
Often see a How to inherit B problem; decide to write, in fact, inheritance is the inheritance of the parents of the attributes and methods, interested friends can refer to ha, I hope to help you copy the code is as follows:


<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Object-Oriented inheritance instance </title>
<script type= "Text/javascript" >
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 ();

}
</script>
<body>
<p> often see questions about inheritance question a How to inherit B decide to write, in fact, inheritance is the inheritance of the properties and methods of the parent-level </p>
</body>

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.