1. Factory function 아래 코드와 같이, 함수에서 객체를 하나 생성한 뒤 리턴해주는 방식을 factory function 이라고 한다. function createUser(email, birthdate) { const user = { email, birthdate, buy(item) { console.log(`${this.email} buys ${item.name}`); }, }; return user; } const user = createUser('juney@kaist.ac.kr', '20021007'); 2. Constructor function new 오퍼레이터를 사용하면, this를 user 객체로 되게끔한다. 따라서 this와 new를 이용하여 다음과 같은 방식으로 constru..
1. forEach 모든 배열 요소 하나씩을 보면서 특정 작업을 수행하는 메소드. const arr = [5, 2, 3]; // index, array는 생략 가능. arr.forEach((element, index, array) => { console.log(element); }); // output: // 5 // 2 // 3 2. map forEach와 비슷하지만, 콜백 함수의 리턴값들로 이루어진 배열을 새로 생성해서 리턴하는 메소드. const arr = [5, 2, 3]; // arr의 각 원소에 5를 더한 값들로 이루어진 새로운 배열 arr2 생성 const arr2 = arr.map((element, index, array) => element + 5); 3. filter 콜백 함수가 리턴하..