댓글 검색 목록

[javascript] closure를 사용하여 저장된 인수로 저장된 키를 호출

페이지 정보

작성자 운영자 작성일 18-09-01 00:01 조회 762 댓글 0
const call = (key, ...args) => context => context[key](...args);
i.e.
Promise.resolve([1, 2, 3])
  .then(call('map', x => 2 * x))
  .then(console.log); //[ 2, 4, 6 ]
const map = call.bind(null, 'map');
Promise.resolve([1, 2, 3])
  .then(map(x => 2 * x))
  .then(console.log); //[ 2, 4, 6 ]

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.