/*
扩展的本地方法
*/
var Natives={
//继承
extend: function(parentClass){
for (var p in parentClass.prototype){
//继承父类中子类没有的
if(!this.prototype[p]){this.prototype[p]=parentClass.prototype[p];
}else{
this.prototype.parent=this.prototype.parent?this.prototype.parent:{};
this.prototype.parent[p]=parentClass.prototype[p];
}
}
},
//扩展
implement: function(params){
for (var p in params){
//扩展父类的原型 会覆盖父类
this.prototype[p]=params[p];
}
}
};
//添加Function 对象 的本地方法
(function(){
for(var p in Natives){
Function.prototype[p]=Natives[p];
}
})();
function Class(params){
var newClass = function(){
this.init.apply(this,arguments);
};
newClass.constructor = Class;
newClass.prototype=params;
newClass.prototype.constructor = newClass;
return newClass;
}
//创建人类
var person=new Class({
name:"fff",
Options:{sex:1},
init:function(a,b){
alert(this.name);
},
say:function(){
alert(this.name);
}
});
var teacher=new Class({
name:"teacher",
init:function(){
//alert(this.name);
},
speack:function(){
alert("i'm teacher");
}
});
teacher.extend(person);
teacher.implement({
play:function(){
alert("i can play");
}
});
var tt=new teacher();
tt.say();</p>
哥们, 你这么写, 谁能看明白?
你看看我的这个Blogs看看能不能找到答案
http://www.cnblogs.com/yangboyu/archive/2010/08/31/1813030.html