Function.prototype.method=function(name,func){
this.prototype[name]=func;
return this;
};
通过给Function.prototype增加方法来使得该方法对所有的函数可用.
alert(Function.prototype.isPrototypeOf(Object)); //true
可以看到,对象其实继承了函数的原型,所以对象可以直接调用.method方法扩展类型的功能,例如:
Array.method("reduce",function(x,y){return x*y/2})
var array1=new Array();
alert(array1.reduce(3,4)); //等于6
参考资料javascript good parts