Skip to content

Instantly share code, notes, and snippets.

@indongyoo
Created April 5, 2018 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indongyoo/eab207950ea45f22cb632be43ddf58a1 to your computer and use it in GitHub Desktop.
Save indongyoo/eab207950ea45f22cb632be43ddf58a1 to your computer and use it in GitHub Desktop.
const p1 = {
id: 1,
selected: true,
name: 'A 반팔티',
price: 12000,
discount: 2000,
quantity: 3
};
// map에 함수를 하나만 전달하여 자동 부분 적용
const gets = map(key => a => a[key]);
// gets 함수를 통해 객체의 key에 할당된 값을 얻어오는 함수들 생성
const [price, discount, quantity, selected] =
gets(['price', 'discount', 'quantity', 'selected']);
console.log( price(p1) ); // 12000
console.log( discount(p1) ); // 2000
console.log( quantity(p1) ); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment