Javascript ES6+ Iterable
Iterable Iterable의 정의 내부 요소들을 공개적으로 탐색(반복)할 수 있는 데이터 구조. [Symbol.iterator] 메소드를 가지고 있다. 아래와 같은 코드들이 iterable한 예이다. const arr = ['a', 'b', 'c'] const set = new Set(['a', 'b', 'c']) const map = new Map([[false, 'no'], [true, 'yes'], ['well', 'soso']]) const str = '문자열도 이터러블하다' ※ Iterable의 의미는 내부 요소들을 공개적으로 반복 및 탐색할 수 있는 데이터 요소를 뜻한다. [Symbol.Iterable] 매소드를 가지고 있는 것이 특징이다. 개체 자신이 iterable한 경우 array,..
2020. 12. 18.
Javascript ES6+ spread operator (펼치기 연산자)
spread operator (펼치기 연산자) var birds = ['eagle', 'pigeon'] var mammals = ['rabbit', 'cat'] var animals = birds.concat('whale').concat(mammals) console.log(animals) const animals2 = [...birds, 'whale', ...mammals] console.log(animals2) //결과: //["eagle", "pigeon", "whale", "rabbit", "cat"] //["eagle", "pigeon", "whale", "rabbit", "cat"] 위와 같이 .concat이라는 메소드를 쓰지 않고도 더 효율적으로 배열을 만들어 낼 수 있다는 것을 볼 수 있다..
2020. 12. 9.
Javascript ES6+ rest parameter (나머지 매개변수)
rest parameter(나머지 매개변수) 구 버전인 ES5에서 썼던 배열을 만들어 주는 argumernt 대신 "...(매개변수)"을 쓴다면 더 쉽게 배열을 만들 수 있다. ...(매개변수) const f = function (x, y, ...rest) { console.log(rest) } f(1, 2, true, null, undefined, 10) //결과; //[true, null, undefined, 10] 위의 결과를 보면 rest 매개변수를 호출한 결과 ...rest만 해줘도 모든 정의된 값들이 배열로서 결과가 나온다는 것을 알 수 있다. const f = function (...rest) { console.log(rest) } f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ..
2020. 12. 9.