[英]Node javascript array deconstruction with custom applied function
[英]Strange behavior with Array deconstruction in Node
我遇到了以下情況引發undefined
錯誤的情況:
...
(str) => {
const [first, second] = str.split('.');
// throws an undefined error
// (can't find a .next of undefined? -- this may not be related)
}
...
因此,我轉換為以下代碼,並且可以正常工作:
...
(str) => {
const temp = str.split('.');
const first = temp[0];
const second = temp[1];
}
...
奇怪的是,如果我將const
轉換為let
,那么它將起作用:
...
(str) => {
let temp = str.split('.');
let [first, second] = temp;
}
...
節點v6.9.1
在節點上測試:
請參閱GitHub上的項目:
查看Travis上的測試結果:
原始海報多次被要求提供顯示此行為的實際數據示例,但未能這樣做。 我和其他人特別要求提供將const
更改為let
時發生該錯誤和不發生該錯誤的Node版本和輸入示例。 由於沒有提供這樣的示例,因此我認為這個問題具有誤導性,並且它所描述的現象實際上並未發生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.