「思考题」模拟实现字符串的trim()函数

String.prototype.trim = function () {
    let reg = /(^s*)|(s*$)/g
    return this.replace(reg, '')
}


// 测试
let str = '    hello word    '
console.log(str.trim())
// "hello word"
原文地址:https://www.cnblogs.com/liea/p/12627792.html