Function.prototype.method=function(name,func){

if(!this.prototype[name]){


this.prototype[name]=func;


}        


        return this;

    }

javascript 缺少一个移除字符串首尾空白的方法。下面我们就扩展一个

 String.method('trim',function(){

       return this.replace(/^\s+|\s+$/g,'');

    });

    var s="            fsdfsss                   ";

    alert(s.trim());