Coffeescript 数组解构忽略一些值
Coffeescript array destructing ignore some value
我在 coffeescript 中使用数组解构并且它工作正常:
[first, second, third] = [1, 2, 3]
console.log "First:" + first, "Second:" + second, "Third:" + third
但我希望能够忽略数组元素。我想做这样的事情:
[, second, third] = [1, 2, 3]
console.log "Second:" + second, "Third:" + third
这在 EcmaScript 6 中是可能的,但如何在 Coffescript 下实现呢?
我刚刚找到了如何做到这一点。这可以通过扩展运算符来完成:
[..., second, third] = [1, 2, 3]
console.log "Second:" + second, "Third:" + third
我在 coffeescript 中使用数组解构并且它工作正常:
[first, second, third] = [1, 2, 3]
console.log "First:" + first, "Second:" + second, "Third:" + third
但我希望能够忽略数组元素。我想做这样的事情:
[, second, third] = [1, 2, 3]
console.log "Second:" + second, "Third:" + third
这在 EcmaScript 6 中是可能的,但如何在 Coffescript 下实现呢?
我刚刚找到了如何做到这一点。这可以通过扩展运算符来完成:
[..., second, third] = [1, 2, 3]
console.log "Second:" + second, "Third:" + third