簡體   English   中英

將參數(變量)傳遞給已經可以從閉包中訪問它們的 function 是否有意義?

[英]Is there a point in passing arguments(variables) to a function which can already access them from its closure?

例如:

let a = 5;
let b = 6;

function sum1() {
    console.log(a + b);
}

function sum2(a, b) {
    console.log(a + b);
}

是否存在其中一個示例不起作用的情況?

在 sum1 中你不能通過 arguments,它會做 5 + 6。但在 sum2 你可以做這樣的事情: sum2(7,8) >> 15 sum2(1,5) >> 6

最好 sum2,因為使用從任何地方調用它並傳遞它 arguments,你想要。

暫無
暫無

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

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