Skip to content

Instantly share code, notes, and snippets.

@sungjaeHong
Created October 5, 2016 08:27
Show Gist options
  • Save sungjaeHong/581d0b138b724ca7af88e8c4a130e00e to your computer and use it in GitHub Desktop.
Save sungjaeHong/581d0b138b724ca7af88e8c4a130e00e to your computer and use it in GitHub Desktop.

#ECMA Script 2015 둘째날 ##Execution Context

  • 함수는 호출시마다 고유한 실행컨텍스트를 생성한 뒤, 이를 활용하여 함수의 내용을 실행해간다.
  • c의 함수는 메모리를 할당했다가 풀면 되지만 javascript의 함수는 c에서 제공한 가짜메모리를 사용하므로 매우 무겁다.
  • javascript의 핵심은 chain이다.
const test = function(){};
test(); new EC_test()	//함수를 호출하면 EC객체를 만들어낸다. 호출100번하면 EC객체는 100개만들어진다.

EC(Execution Context) =		LexicalEnvironment
							VariableEnvironment 
								
							code evaluation state
							Function
							Realm
/*	
	LexicalEnvironment : Environment Record + outer Lexical Environment + Generator
	내부의 key를 찾아가는 알고리즘으로 동작한다. 
	Environment Record : 현재 스코프의 변수들
	outer Lexical Environment : 현재 스코프의 상위 변수들
*/

const a = function(){
	const b= function(){}
	b();
};
a();

/*
1. 브라우저를 실행하면 EC_global이 생성된다.
2. a()를 실행하면 EC_a가 생성되며 outer Lexical Environment는 EC_global의 Environment Record를 바라보고있다.
3. a가 실행되며 b()가 호출되면 EC_b가 생성되며 EC_b의 Lexical Environment는 EC_a의 Environment Record를 바라봄.
*/

##Environment Record Type

  • Object Environment Record : 객체형 레코드
  • Declarative Environment Record : 참조형 레코드

##Arrow function

  • thisBinding을 동적으로 하지 않고 lexical Record의 것을 사용하도록 고정됨.
    class구문 : 클래스, 메소드를 생성함
    arrow function : 람다를 생성함
    object method : 해당 object의 메소드를 생성함
class {
	constructor:{}
	method:{}
}

const obj = {
	method(){}
}

const test =v=>{};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment