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;

 

posted on 2015-02-02 00:35  爱生活的夜  阅读(214)  评论(0编辑  收藏  举报