如何将我之前创建的现有函数导入到函数中?
如何将数组导入到函数中?
function namarray (arr[])
{}
function namfunc (fun())
{}
如何用正确的语法编写它?
最佳答案
这两种情况都是一样的,您将所需的内容作为参数
传递给函数。对于函数,您只需传递函数名称,因此不要包含 ()
- 稍后当您想要调用该函数时会使用它
您当然可以选择将输入保存到函数内的变量
// 1) How to import into function an existing function that I have alreqdy created before ?
// 2) How to import into function an array ?
function testFunction () {
return 'I am the test function';
}
function questionOne (input) {
console.log(input());
}
function questionTwo (input) {
console.log(`I was given the input ${input}, which is an ${typeof input}`);
}
questionOne(testFunction);
questionTwo([1,2,3]);
// In reply to comment
let longArray = [1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333];
questionTwo(longArray);
关于javascript - 如何将数组和函数导入到函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58886109/