javascript ES2019:优化`matchAll`实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES2019:优化`matchAll`实现相关的知识,希望对你有一定的参考价值。
export default Function.call.bind(
// /* TODO: Uncomment eventually */ String.prototype.matchAll ||
{
/**
* @this {string}
* @param {RegExp | string} pattern
*/
*matchAll() {
const matcher = arguments[0] && (arguments[0] instanceof RegExp ? arguments[0] : RegExp(arguments[0], 'g'));
const string = String(this);
for (
let match, lastIndex = ((matcher.lastIndex = null), -1);
lastIndex <
((match = matcher.exec(string)) ? (lastIndex = matcher.lastIndex + (match[0].length === 0)) : lastIndex);
yield match, matcher.lastIndex = lastIndex
);
},
}.matchAll,
)
以上是关于javascript ES2019:优化`matchAll`实现的主要内容,如果未能解决你的问题,请参考以下文章
ES2019 中的 JavaScript 新特性
JavaScript:ES2019 的新特性
[Javascript] Automate the process of flattening deeply nested arrays using ES2019's flat method(
2019年JavaScript性能优化解析
03JavaScript程序设计修炼之道 2019-06-02_15-20-09 for each 数组es6的方法
ES---多索引设计(思路)