【模拟类】
=======================================================
var Class = function(parent){
var klass = function(){
this.init.apply(this,arguments);
};
if (parent){
var subclass = function(){};
subclass.prototype = parent.prototype;
klass.prototype = new subclass;
}
klass.prototype.init = function(){};
klass.fn.parent = klass;
klass.extend = function(obj){
var extend = obj.extended;
for (var i in obj){
klass[i] = obj[i];
}
if (extended) extended(klass);
};
klass.include = function(obj){
var include = obj.included;
for(var i in obj){
klass.fn[i] = obj[i];
}
if(included) included(klass);
};
klass.proxy = function(func){
var self = this;
return (function(){
return func.apply(self, arguments);
});
};
klass.fn.proxy = klass.proxy;
return klass;
}
【改变函数的上下文】
==============================================
var proxy = function(func,thisObject){
return (function(){
return func.apply(thisObject , arguments);
});
}