簡體   English   中英

不返回分配-何時禁用

[英]no-return-assign - when to disable

我正在嘗試在此對象數組中傳遞ID:

const children = [{name: Jack, age: 8}, {name: Joe, age: 6}];
children.forEach((child) => (child.id = v4()));

我不斷收到eslint error no-return-assign這確實讓我煩惱(雙關語)

我試過了:

children.forEach(child => child.id = v4());

children.forEach((child) => (child.id = v4())); 

children.forEach(child => (child.id = v4()));

children.forEach((child) => {
    return child.id = v4()
});

沒有工作。

我應該禁用eslint嗎? 有解決方法嗎?

好吧,不要從回調函數返回任何東西。 寫吧

children.forEach(child => {
    child.id = v4();
});

甚至更簡單

for (const child of children) {
    child.id = v4();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM