ES2023
Array.prototype
增加以下方法,不改变原数组,而返回一个原数组的拷贝。
toReversed(),对应reverse()toSorted(compareFn),对应sort()toSpliced(start, deleteCount, ...items),对应splice()with(index, value),对应splice(index, 1, value)findLast(fn),从数组的最后一个成员开始,依次向前寻找,返回找到的成员findLastIndex(fn),从数组的最后一个成员开始,依次向前检查,返回找到的成员索引
以上新增方法,除 toSpliced() 外,TypedArray.prototype 同样支持。
下面是示例
js
const sequence = [1, 2, 3]
sequence.toReversed() // [3, 2, 1]
const outOfOrder = [3, 1, 2]
outOfOrder.toSorted() // [1, 2, 3]
const array = [1, 2, 3, 4]
array.toSpliced(1, 2, 5, 6, 7) // [1, 5, 6, 7, 4]
const correctionNeeded = [1, 1, 3]
correctionNeeded.with(1, 2) // [1, 2, 3]Hashbang
#! 称为 shebang,或者 hashbang。
tc39/proposal-hashbang 明确称为 hashbang ,因为 shebang 没有语义,可能是大家都这么拼读于是就有了这种拼读方法。
hashbang 是 Unix 系统事实上的标准,在 Node.js 脚本文件中广泛使用。
hashbang提案让 JS 引擎把这一行理解为注释。