본문 바로가기
모바일 APP/React-Native

ES6 화살표 함수

by 살길바라냐 2021. 12. 9.
// 함수 표현식

function add(num) {
	return function (value) {
     return num + value;
    };
}


// 화살표 함수 표현식
const add = num => value => num + value;

 

가장중요!!

화살표 함수는 콜백 함수의 this 범위로 생기는 
오류를 피하기 위해 bind() 하수를 사용하여 
this 객체를 전달하는 과정을 포함한다. 

class test {
 val = 10;
 constructor() {
 	const add1 = function(one, two) {
     return this.val + one + two
    }.bind(this)
    const add2 = (one, two) => this.val + one + two
 }
}

 

728x90
반응형

'모바일 APP > React-Native' 카테고리의 다른 글

아이폰 안드로이드 디스플레이 길이  (0) 2021.12.27
ES6 구조 분해와 구조 할당  (0) 2021.12.09
가변 변수와 불변 변수  (0) 2021.12.09
전개 연산자  (0) 2021.12.07
고차함수 (Currying)  (0) 2021.12.04