Skip to content

Instantly share code, notes, and snippets.

@as3long
Last active August 29, 2015 14:05
Show Gist options
  • Save as3long/deea376830e01105e4f2 to your computer and use it in GitHub Desktop.
Save as3long/deea376830e01105e4f2 to your computer and use it in GitHub Desktop.
简单的继承写法 // source http://jsbin.com/qiteh/12
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var A={};
A.Object=function(obj){
function F() {}
return function (obj) {
F.prototype = obj;
return new F();
};
}
A.extend = function(r, s) {
var sp = s.prototype, rp = A.Object(sp);
r.prototype = rp;
}
A.class=function(superType,func){
var Fobject=function(){
superType.call(this);
func.call(this);
}
A.extend(Fobject,superType);
A.extend(Fobject,func);
return Fobject;
}
//测试部分
var Class1=function(){
this.color=[];
this.fun1=function(){
return 1;
}
}
var Class2=A.class(Class1,function(){
this.abc=[];
this.fun1=function(){
return 2;
}
})
var c1=new Class2();
c1.abc.push("1");
var c2=new Class2();
console.log(c2.fun1());
</script>
</body>
</html>
var A={};
A.Object=function(obj){
function F() {}
return function (obj) {
F.prototype = obj;
return new F();
};
}
A.extend = function(r, s) {
var sp = s.prototype, rp = A.Object(sp);
r.prototype = rp;
}
A.class=function(superType,func){
var Fobject=function(){
superType.call(this);
func.call(this);
}
A.extend(Fobject,superType);
A.extend(Fobject,func);
return Fobject;
}
//测试部分
var Class1=function(){
this.color=[];
this.fun1=function(){
return 1;
}
}
var Class2=A.class(Class1,function(){
this.abc=[];
this.fun1=function(){
return 2;
}
})
var c1=new Class2();
c1.abc.push("1");
var c2=new Class2();
console.log(c2.fun1());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment