发现对对象继承或拷贝的时候,总是要$点来点去好麻烦,我的解决办法如下:
(function(){
Object.prototype.extend = function(o){
$.extend(true,this,o||{});
};
Function.prototype.extend = function(o){
$.extend(true,this,o||{});
};
})()
使用:
var a = new Object();
a.extend({info:'yeah!'});
var func = function(){};
var f = new func();
f.extend({info:'yeah!'});
结果:
a:
Object {info: "yeah!", extend: function}
f:
func {info: "yeah!", extend: function}
新手,如有错误,请指正!