Quick tip: reusable Array search predicates - JASON Format

arr.filter(callback(element[, index[, array]])[, thisArg])

배열 메서드의 2번째 인자 thisArg는 콜백의 this가 된다 — 비교할 값을 this로 받는 function 하나를 여러 검색에 재사용하는 트릭. 화살표 함수는 this가 없어 thisArg가 무시된다1. 단 화살표 함수보다 느릴 수 있다2.


Footnotes

  1. Array — Iterative methods | MDN: “The thisArg argument is irrelevant for any callbackFn defined with an arrow function, as arrow functions don’t have their own this binding.” ↩

  2. Quick tip: reusable Array search predicates: “the performance of this approach can be worse than using an Arrow Function without some restrictions.” ↩

#8