掛載到 RegExp 原型對象上
使用方式:
let reg = /\d+/g
reg.execAll(str)
~function () {
function execAll (str = '') {
let list = [],temp = null
temp = this.exec(str)
// 是否使用了 g
if (!this.global) return temp ? temp[0] : []
while (temp) {
list.push(temp[0])
temp = this.exec(str)
}
return list
}
RegExp.prototype.execAll = execAll
}()