简体   繁体   English

如何找到在 function 中声明的参数?

[英]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.

相关问题 我如何找到在哪个JavaScript中声明了任何变量或函数? - How do i find in which javascript any variable or function is declared? 如何访问在 function 中声明的变量 - How do I access a variable declared inside a function 如何将在父页面中声明的函数注入到iframe中,然后调用它? - How do I inject a function declared in the parent page into an iframe, then call it? 如何使用参数在对象上定义函数? - How do I define a function on an object with parameters? 如何找出对象中是否声明了函数? - How to find out if there is a function declared in an object? 如何将参数传递给声明为左= function()的函数 - How to pass parameters to a function declared like left = function() 如何确保正确的参数传递给循环中声明的函数调用? - How to ensure the right parameters is passed to a function call declared in a loop? 如何使函数使用在另一个函数JavaScript / jQuery上声明的变量 - How do I make a function use a variable that was declared on another function JavaScript/jQuery 如何编写带有参数的同步函数作为异步函数(Javascript)? - How do I write a synchronous function with parameters as an asynchronous function (Javascript)? 如何使用两个参数创建一个函数来查找节点是否存在? - How can I make a function with two parameters to find if a node exists?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM