How this parameter knows the argument

廉价感情. 提交于 2020-08-10 19:16:48

问题


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)));

回答1:


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.

This here would do the same thing:

console.log(arr.filter((elem) => {
    return elem.length > 6;
}));


来源:https://stackoverflow.com/questions/63031317/how-this-parameter-knows-the-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!