问题描述
编辑:,已关闭一天后由jashkenas。所以外卖是基本上按预期工作。
made a github issue, it got closed a day later by jashkenas. So the takeaway is "working as intended" essentially.
coffee> arr
[ 0,
1,
2,
3,
'A',
'K' ]
coffee> arr[...]
[ 0,
1,
2,
3,
'A',
'K' ]
coffee> arr[..]
[ 0,
1,
2,
3,
'A',
'K' ]
,那些应该是不同的。
According to the docs, those should be different.
产生的两个 slice
语句是相同的。看起来 ..
应该产生 .slice(0)
和 ...
应该产生 .slice(0,-1)
我缺少什么或看到错误?
The two slice
statements that are produced are the same. Seems to me that ..
should produce .slice(0)
and ...
should produce .slice(0, -1)
Am I missing something or seeing a bug?
1.7.1
推荐答案
文档然后继续说:
与你看到的。数组的长度为6,因此:
This is consistent with what you're seeing. The length of your array is 6 so:
-
[..]
到[0..6]
,它将编译为.slice(0,7)
-
[...]
相当于[0 ... 6]
.slice(0,6)
[..]
is equivalent to[0..6]
which would compile to.slice(0,7)
[...]
is equivalent to[0...6]
which would compile to.slice(0,6)
.slice(0,6)
和 .slice(0,7)
返回所有元素,到 .slice(0)
,这是 [..]
和 ..]
编译为
With an array of length 6, both .slice(0,6)
and .slice(0,7)
return all elements and so both are equivalent to .slice(0)
, which is what both [..]
and [...]
compile to.
如果省略的第二个索引默认为数组大小减1 ,但事实并非如此。
What you are expecting would be the case if an omitted second index defaulted to the size of the array minus 1, but this is not the case.
这篇关于数组的[..]和[...]之间没有区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!