Arrow Function => 이 문법은 주로 함수를 파라미터로 전달할 때 유용. this값이 다른 것이 큰 특징이다.
일반함수는 자신이 종속된 객체를 this로 가리키지만 화살표 함수는 자신이 종속된 인스턴스를 가리킨다.
function BlackDog(){ this.name = 'White'; return { name : 'Black'; bark: function(){ console.log(this.name + ' Bark!'); } } } const blackDog = new BlackDog(); blackDog.bark(); // Black Bark! |
function WhiteDog(); this.name = 'White'; return { name : 'Black'; bark: () => { console.log(this.name + ' Bark!'); } } } const whiteBog = new WhiteDog(); whiteDog.bark(); // White Bark! |
Spread operator > 나열한 자료를 추출하거나 연결할 때 사용한다. 배열, 객체, 변수 앞에 마침표 세 개로 선언한다.
다만 배열, 객체, 함수 인자 표현식"[], {}, ()" 안에서만 사용된다.
var array1 = ['one', 'two']; var array2 = ['three', 'four']; var combined = [...array1, ...array2]; // combined = ['one', 'two', 'three', 'four']; var [first, second, three = 'empty', ...others] = array1; // first = 'one', second = 'two', three = 'empty', others = [] |
'Programming > Javascript' 카테고리의 다른 글
[ES6] Enhanced object property (0) | 2021.10.07 |
---|---|
[ETC] 비동기처리 (Callback / Promise) (0) | 2021.10.07 |
[ETC] Object, Class, Instance (0) | 2021.10.07 |
드림코딩 by 엘리. JavaScript 기초 강의(10) - JSON 개념 정리와 활용방법 및 유용한 사이트 공유 (0) | 2021.10.07 |
드림코딩 by 엘리. JavaScript 기초 강의(9) - 유용한 10가지 배열 함수들, Array APIs 총 정리 (0) | 2021.10.07 |