此参数如何知道参数 [英] How this parameter knows the argument
本文介绍了此参数如何知道参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对elem如何获得arr的值感到困惑吗?
Im confused with how the elem get the value of arr?
function lengGreaterThan(num) {
function lengGreaterThanNum(elem) {
return elem.length > num;
}
return lengGreaterThanNum;
}
let arr = ['Justin', 'caterpillar', 'openhome'];
console.log(arr.filter(lengGreaterThan(6)));
推荐答案
这是一种非常令人困惑的编写方式,但实际上,您只是将一个带有一个参数的函数放入过滤器函数中.
That is a really confusing way of writing it, but essentially you are just putting a function that takes one parameter into the filter function.
这将执行相同的操作:
console.log(arr.filter((elem) => {
return elem.length > 6;
}));
这篇关于此参数如何知道参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文