Replies: 10 comments 3 replies
-
一些在进入stage1之后需要进一步探讨的问题: 是否需要引入双端迭代,还是用更简单的方式将
|
Beta Was this translation helpful? Give feedback.
-
请问本提案能解决那些典型 use case? |
Beta Was this translation helpful? Give feedback.
-
@septs 首先因为python、ruby、coffee早就支持 然后具体的case,除了直接解构拿后面的项,最主要的就是函数参数,末尾固定参数,前面有不定参数: string.replace(pattern, (fullMatch, ...submatches, matchIndex, fullString) => {
// `matchIndex` is always the second to last param (the full string is the last param).
// There may be many submatch params, depending on the pattern.
}) 常见还有node.js里常见的固定末尾参数为callback,而前面为不定个数参数;某些库的api可能末尾固定参数为一个option对象,前面为不定个数位置参数。 |
Beta Was this translation helpful? Give feedback.
-
OK
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
const [, ...rest] = arr 代表去掉第一个元素 const [...rest, ] = arr 那这个呢? |
Beta Was this translation helpful? Give feedback.
-
一般而言,尾随逗号在js里是忽略的,因此和没有尾随逗号是一样的。比如 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
我计划在下次TC39会议(2022年7月)对本提案做更新陈述。主要有几个想改动(和细化)的点。 第一,将 "back" 改为 "last"。一开始用 next("back") 是沿袭了 Rust 的 第二,考虑使用单独的 第三,判定是否是双端迭代器的机制(当双端解构实际调用了一个非双端迭代器应该扔TypeError)。在最初,我引入了 第四,其他如现有内建迭代器升级到支持双端基本没有啥特别大问题,Iterator helpers升级到支持双端有一些小问题,留待以后再说。 |
Beta Was this translation helpful? Give feedback.
-
我比较好奇的是,对应的生成器函数该怎样写? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
提案repo:https://github.com/hax/proposal-deiter
计划在下周的TC39会议上争取进stage 1。
当前解构中
...rest
必须在最后一个参数的位置,此提案允许...rest
出现在任何一个位置(不过仍然只能出现一次)。比如
let [first, ...rest, last] = [1, 2, 3, 4]
,结果first
为1
、rest
为[2, 3]
、last
为4
。其底层机制使用双端迭代器。
对于
let [first, ...rest, last] = iterable
不是调用iterable[Symbol.iterator]()
而是调用iterable[Symbol.deIterator]()
,其应该返回一个双端迭代器。双端迭代器应支持从两端进行迭代,next('back')
表示从尾端迭代:这样
let [first, ...rest, last] = iterable
差不多相当于:Userland要实现双端迭代器,需要使用
function.sent
(stage 2)特性。以上。
Beta Was this translation helpful? Give feedback.
All reactions