Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES2023 #9

Open
luoway opened this issue Jan 29, 2024 · 0 comments
Open

ES2023 #9

luoway opened this issue Jan 29, 2024 · 0 comments
Labels
deploy deploy to gh-page

Comments

@luoway
Copy link
Owner

luoway commented Jan 29, 2024

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 同样支持。

下面是示例

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 引擎把这一行理解为注释。

参考资料

@luoway luoway added the deploy deploy to gh-page label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy deploy to gh-page
Projects
None yet
Development

No branches or pull requests

1 participant