《高性能javascript》中推薦的javascript字符串trim方法(假設沒有原生方案)

String.prototype.trim = function() { var str = this.replace(/^\s+/, ""), end = str.length - 1, ws = /\s/; while (ws.test(str.charAt(end))) { end--; } return str.slice(0, end + 1); } 解析
相關文章
相關標籤/搜索