// 使用正则表达式
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trimLeft = function() {
return this.replace(/(^\s*)/g, "");
}
String.prototype.trimRight = function() {
return this.replace(/(\s*$)/g, "");
}
```
网友评论