将猫传递给func如何返回回调?
let animal = '';
const fetchAnimal = func => {
func('cats');
};
fetchAnimal(name => {
//logs cats to the console
console.log(name);
});
答案 0 :(得分:0)
在这里,我们将函数作为参数传递给映射到fetchAnimal
变量的函数调用中的func
。因此,当您调用func('cats')
时,它最终将使用cats
作为参数调用函数调用期间传递的函数,该参数映射到变量name
。
const fetchAnimal = func => {
func('cats');
};
fetchAnimal(name => {
console.log(name);
});