개발노트

ES6 본문

javascript/ES6

ES6

aloha2jh 2021. 4. 19. 11:33

hooks 문법

created : function(){}

created (){ }

 

화살표함수 this차이점

js는 기본적으로 전역변수로 시작하는데, 변수선언하면 최상단 브라우저객체인window에 담아짐

 

(1) this 도 이 window를 가리키고

(2) function내의 this 도 전역this임

function sum(a, b){
	console.log(this);
    return a+b;
}

 

const sum = (a,b)=> { console.log(this); return a+b };

>>undefined

 

 

(3) 생성자로 생성하는 함수의 this

function Vue(el){
  console.log(this);
  this.el = el;
}

new Vue('#app');

 

(4) 비동기 처리의 this

비동기호출전 this->window

호출후-> 기존this에서 벗어난 this가 생김 undefined

(그래서 비동기호출함수 외부의 this를 가져다가 연결해서 사용했음)

 

ES6로 호출후-> 호출되는위치의 this를가져옴

(가져올필요없음 !)

 

 

use strcit 

developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Strict_mode

 

Strict mode - JavaScript | MDN

Strict mode 가끔 엄격하지 않은 기본값을 "느슨한 모드(sloppy mode)"라고 부르기도 합니다. 공식적인 용어는 아니지만 혹시 모르니 알아두세요. ECMAScript 5 에서 소개된 JavaScript 의 엄격모드는 JavaScrip

developer.mozilla.org