String.prototype.trim

/*内置对象添加方法:String.prototype.trim(给String添加一个trim方法)
*^这个是以什么什么开头
*$这个是以什么什么结尾
*‘/s是String /d是数字’
*replace(/^s+/ , "")把以字符开头的字符串替换为空字符串,
*replace(/s+$/ , "")把以字符结尾的字符串替换为空字符串,
*/
String.prototype.trim = function()
{
return this.replace(/^s+/ , "").replace(/s+$/ , "");
}

原文地址:https://www.cnblogs.com/excellencesy/p/7877847.html