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.