[英]How do I find parameters declared in a function?
I'm working on the web speech api for my own projects.我正在为我自己的项目编写 web 演讲 api。 I'm confused by this function:我对这个 function 感到困惑:
colors.forEach(function(v, i, a){
console.log(v, i);
colorHTML += '<span style="background-color:' + v + ';"> ' + v + ' </span>';
});
I understand that v, i & a are parameters, but I can't see where they are declared.我知道 v, i & a 是参数,但我看不到它们的声明位置。 They are used in the function and I want to understand how they are used.它们在 function 中使用,我想了解它们是如何使用的。
Many thanks非常感谢
Edit: parameters within the parentheses编辑:括号内的参数
How do I find parameters declared in a function?如何找到在 function 中声明的参数?
By reading the documentation .通过阅读文档。
but I can't see where they are declared但我看不到它们的声明位置
They are declared right there in the function expression that creates the function you pass as a callback.它们在 function 表达式中声明,该表达式创建您作为回调传递的 function。
They get values when the function is called.它们在调用 function 时获得值。
arr.forEach(callback(currentValue [, index [, array]])[, thisArg])
So v
is the current value being looped over, i
is its index in the array, and a
is the array itself.所以v
是循环的当前值, i
是它在数组中的索引, a
是数组本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.