Home > Web Front-end > JS Tutorial > JavaScript object-oriented (2)_javascript skills

JavaScript object-oriented (2)_javascript skills

WBOY
Release: 2016-05-16 19:24:35
Original
1031 people have browsed it

There was too much nonsense written in the previous article and it was poorly written. Let’s talk about inheritance this time. We knew the prototype in the previous section. Now I start from the prototype to implement the method


function occupation(){
var Notes="Go to work every day";
}
occupation.prototype.work=function(name){
return name "Go to work" ;
}
occupation.prototype.off duty=function(){
return "off duty";
}
Function.prototype.extend=function(superClass){
for(var $p in superClass.prototype){
this.prototype[$p]=superClass.prototype[$p];
}
delete $p;
}
function actor(){
}
Actor.prototype.On TV=function(person){
return person "On TV";
}
function clown(){
}
Clown. prototype.line=function(){
return "Exaggerated smile";
}

Actor.extend(occupation);

var Zhang San=new Actor();

alert(Zhang San. go to work("Zhang San"));

clown.extend(actor);

var Xiaozhuo=new clown();

alert(Xiao Zhuo. Work("Xiao Zhuo"));

alert(Xiao Zhuo. Outfit());

alert(Xiao Zhuo. Go to TV("Xiao Zhuo. Zhuo's show"));
//-->
īpt>


Just wrote a small example of inheritance.

In this way, it is a bit absurd to do this without considering the parent class method and the subclass method. Let me write this

first, and then write later.

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