base.js --implementation of inheritance ==========================
[Note]: After inheritance, if the parent class is a class , it will inherit its properties, methods (including those declared with prototype), and static methods, otherwise only properties and methods will be inherited.
Object.prototype.extendf= function (a,b) {
if(!a||!b) return;
var fa = typeof a=="function";
var fb = typeof b=="function";
var cha = function (a,b){
for(var c in b){
if(a[c]==undefined)//Subclass rewrite
a[c]=b[c];
}
return a; //Return the inherited object
}
if(fa&&fb){
b.apply(this,a.arguments);
cha(a,b );
this["base"] =new b;//Access the parent class through base
return cha(this,b.prototype);
}
else if(!fa&&fb){
cha(a,new b);
a["base"]= new b;
return cha(a,b);
}else if(fa&&!fb){
cha (a,b);
this["base"]=b;
return cha(this,b);
}else if(!fa&&!fb){
a["base" ]=b;
return cha(a,b);
}
}
Test page: Usage
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