首页 > 代码库 > [javascript]String添加trim和reverse方法

[javascript]String添加trim和reverse方法

function trim() {    var start, end;    start = 0;    end = this.length - 1;     while(start <= end && this.charAt(start) == " " ) {        start ++;      }     while(start <= end && this.charAt(end) == " " ) {        end --;    }     return this.substring(start, end+1);} function reverse() {    var str = "";    var end = this.length - 1;    for(;end >= 0; end --) {        str = str + this.charAt(end);    }     return str; } String.prototype.trim = trim;String.prototype.reverse = reverse;

 

[javascript]String添加trim和reverse方法