Javascript 함수(function) 개념, 호출패턴, this, prototype, scopeYoung-Beom RheeJavascript의 함수(Function)의 기본개념과, 호출패턴에 따라 달라지는 this, 상속을 가능하게 해주는 prototype, 다른 언어와 다른 scope에 대해 알아봅니다.
스파르탄스터디 E04 Javascript 객체지향, 함수형 프로그래밍Young-Beom RheeJavascript 객체지향, 함수형 프로그래밍에 대해서 알아봅니다.
prototype을 이용하여 상속을 구현하는 방법, 그리고 Closure와 Function을 이용한 강력한 함수형(Functional) 프로그래밍
골때리는 자바스크립트 발표자료욱진 양Sorry. for koreans only. I'll add english short description. or just visit http://wtfjs.com
아오 썅.
정정사항입니다.
객체 동일비교는 항상 valueOf 결과물로 나온 비교로 하는 데다가,
객체와 배열은 valueOf 해봐야 객체로 나오기 때문에
객체와 배열은 == 하나 === 하나 같은 비용으로 비교합니다.
[1,2,3]==[1,2,3] 은 false가 되므로
[1,,,2]==[1,undefined,undefuned,2] 는 무조건 false로 나옵니다.
Javascript introduction, dynamic data type, operatorYoung-Beom Rhee대상 : Javascript를 언어로 처음 접하는 개발자
범위 : Javascript의 흐름, 문맥(Context)를 모르면 이해할 수 없는 Dynamic typing(동적 데이터 타입), 멘붕을 마음껏 선사할 헷갈리는 연산자
프론트엔드스터디 E03 - Javascript intro.Young-Beom RheeJavascript 흐름, 동적데이터타입(Dynamic typing), 연산자, 객체, 배열, 동적 파라미터, Script 선언위치 등 Javascript를 처음 접했을때 꼭 이해해야 되는 내용들에 대해서 알아봅니다.
C++ Concurrency in Action 9-2 Interrupting threadsSeok-joon YunC++ Korea
C++ Concurrency in Action
Study
Chapter 09 Advanced thread management
9.2 Interrupting threads
Javascript introduction, dynamic data type, operatorYoung-Beom Rhee대상 : Javascript를 언어로 처음 접하는 개발자
범위 : Javascript의 흐름, 문맥(Context)를 모르면 이해할 수 없는 Dynamic typing(동적 데이터 타입), 멘붕을 마음껏 선사할 헷갈리는 연산자
프론트엔드스터디 E03 - Javascript intro.Young-Beom RheeJavascript 흐름, 동적데이터타입(Dynamic typing), 연산자, 객체, 배열, 동적 파라미터, Script 선언위치 등 Javascript를 처음 접했을때 꼭 이해해야 되는 내용들에 대해서 알아봅니다.
C++ Concurrency in Action 9-2 Interrupting threadsSeok-joon YunC++ Korea
C++ Concurrency in Action
Study
Chapter 09 Advanced thread management
9.2 Interrupting threads
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-1탑크리에듀(구로디지털단지역3번출구 2분거리) 자바에서 모델객체를 생성할 때 setter/getter/toString/hashCode/equals 메소드를 만드는데 이럴 경우 클래스 파일의 소스가 길어지고 복잡해지는데 이를 해결하기 위해 롬복(Lombok)을 사용한다.
클래스 안에 있는 필드에 대해 Getter, Setter의 생성이나, toString(), equals(), hashCode() 메서드, 생성자를 자동으로 생성 해준다.
설치
http://projectlombok.org/download.html 에서 jar 파일을 다운로드 후 실행(더블클릭해서 실행 안되면 javaw –jar lombok.jar로 실행하자)
maven의 설정 파일에 의존성 추가
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version></dependency>
Gradle의 설정 파일에 의존성 추가
Compile('org.projectlombok:lombok:1.16.6')
스프링 부트를 사용한다면 프로젝트 생성시 두번째 화면에서 Core -> Lombok을 선택하면 자동으로 라이브러리가 추가된다.
어노테이션
@Getter : Getter 메소드를 생성해 준다.
@Setter : Setter 메소드를 생성해 준다.
getter 는 필드값을 리턴하며 필드명이 name 일때 게터 메소드 이름은 getName (name이 boolean 일때는 isName), 기본 setter는 filed 명이 name 일때 setName이 된다. return type은 void 이며 field 와 동일한 type의 라파미터를 한 개만 입력받는다. 생성된 getter/setter method 의 기본 접근레벨은 AccessLevel 키워드를 명시적으로 지정하지 않았다면 public 이며 Accesslevels 은 PUBLIC, PROTECTED, PACKAGE, and PRIVATE 중에 설정할 수 있다.
3. Execution context
실행 가능 코드(Executable Code)
1. Global code
2. eval code
3. Function code
를 만났을 때, Execution context가 하나씩 생성
이 때, 세 가지 Components를 생성
1. LexicalEnvironment
2. VariableEnvironment
3. ThisBinding
=> Running execution context이 대상
1. 개요
6. 함수가 실행될때,
ExecutionContext(3개의
Component로 구성) 생성
ExecutionContexts = {
LexicalEnvironment : {}
, VariableEnvironment : {}
, ThisBinding : {}
}
debugger;
var sayHello = 'Hello, ';
function person(){
var first = 'David',
last = 'Shariff';
function firstName(){
return first;
}
function lastName(){
return last;
}
console.log(sayhello + firstName() + ' ' + lastName());
}
person();
2. Execution Context
7. Lexical Environment
=> 자바스크립트 코드의 실행환경, 범위를 구조적으로 엮으면서 독립
적으로 실행하기 위한 환경
LexicalEnvironment = {
EnvironmentRecords : {} // 실행 중인 함수 안의 함수, 변수 저장
, outerEnvironmentRecords : {} // 가장 근접한 스코프
}
3. Lexical Environment
firstName()이 실행중이라면,
outerEnvironmentRecords는
person()의 EnvironmentRecords
가 된다
8. Environment Records
=> 함수와 변수를 기록하는 곳
EnvironmentRecords : {
DeclarativeEnvironmentRecord : {}
, ObjectEnvironmentRecord : {}
}
DeclarativeEnvironmentRecord : function, 변수, catch 문
ObjectEnvironmentRecord : binding object의 function, 변수, with 문
person()이 실행중이라면,
DeclarativeEnvironmentRecord
에는 first, last, firstName,
lastName이 binding
ObjectEnvironmentRecord 에는
sayHello이 binding
3. Lexical Environment
9. VariableEnvironment
=> LexicalEnvironment 와 같지만 다르다?
4. Variable Environment, This Binding
function, 변수 식별자(Identifier)이 binding 되
는 점은 같다.
LexicalEnvironment의 값은 실행 중에 변하지만,
VariableEnvironment는 변하지 않는다.
ThisBinding
2번째 시간에 배웠던 호출한 함수가 속한 오브
젝트를 참조한다는 기본원리와 동일
10. VariableEnvironment
=> LexicalEnvironment 와 같지만 다르다?
4. Variable Environment, This Binding
function, 변수 식별자(Identifier)이 binding 되
는 점은 같다.
LexicalEnvironment의 값은 실행 중에 변하지만,
VariableEnvironment는 변하지 않는다.
ThisBinding
2번째 시간에 배웠던 호출한 함수가 속한 오브
젝트를 참조한다는 기본원리와 동일
11. ExecutionContext 정리
ExecutionContext = {
LexicalEnvironment : {
EnvironmentRecords : { // 실행 중인 함수 안의 함수, 변수 저장
DeclarativeEnvironmentRecord : {} // function, 변수, catch 문
, ObjectEnvironmentRecord : {} // 글로벌 오브젝트의 function, 변수, with문
}
, outerEnvironmentRecords : {} // 가장 근접한 스코프
}
, VariableEnvironment : {} // function, 변수 식별자(Identifier)가 binding
, ThisBinding : {} // 호출한 함수가 속한 오브젝트를 참조
}
좋은 코딩 방식 = outerEnvironmentRecords 참조의 최
소화
1. 함수에서 사용할 함수, 변수를 함수 안에 작성
2. 어렵다면 한 단계 위의 Scope에 작성
3. 전역 변수사용 최소화
3. Lexical Environment
12. Declaration Binding Instantiation
모든 Execution context는 선언된 function, 변수를
VariableEnvironment의 Environment Record에 바인딩 한다.
특별히 function은 parameter 또한 바인딩 한다.
5. Declaration Binding Instantiation
debugger;
var sayHello = 'Hello, ';
function person(){
var first = 'David', last = 'Shariff';
function firstName(){
return first;
}
function lastName(){
return last;
}
console.log(sayhello + firstName() + ' ' + lastName());
}
person();
16. Declaration Binding Instantiation
Quiz.
debugger;
var obj = {};
obj.sports = function(one, two, arguments){
console.log(arguments); // ?
}
obj.sports(11, 22, 33);
5. Declaration Binding Instantiation
DeclarativeEnvironmentRecord에 이미 존재하는 것들은
설정하지 않는다.
17. Declaration Binding Instantiation
Quiz.
debugger;
var obj = {};
obj.sports = function(one, two, arguments){
console.log(arguments); // ?
}
obj.sports(11, 22, 33);
5. Declaration Binding Instantiation
DeclarativeEnvironmentRecord에 이미 존재하는 것들은
설정하지 않는다.
18. Closure – Closure를 사용하지 않았을 때
var uniqueId = function(){
if(!arguments.callee.id){
arguments.callee.id = 0;
}
return arguments.callee.id++;
}
uniqueId(); // 0
uniqueId(); // 1
uniqueId(); // 2
// id를 0으로 초기화 할 수 있을까?
6. Closure
19. Closure – Closure를 사용하지 않았을 때
var uniqueId = function(){
if(!arguments.callee.id){
arguments.callee.id = 0;
}
return arguments.callee.id++;
}
uniqueId(); // 0
uniqueId(); // 1
uniqueId(); // 2
// id를 0으로 초기화 할 수 있을까?
uniqueId.id = 0;
uniqueId(); // 0
6. Closure
20. Closure – Closure를 사용했을 때
var uniqueId = (function(){
var id = 0;
return function(){
return id++;
}
})();
uniqueId(); // 0
uniqueId(); // 1
uniqueId(); // 2
// id를 0으로 초기화 할 수 있을까?
6. Closure
21. var uniqueId = (function(){
var id = 0;
return function(){
return id++;
}
})();
uniqueId(); // 0
uniqueId(); // 1
uniqueId(); // 2
// 0으로 초기화
uniqueId.id = 0 // ?
6. Closure
Closure – Closure를 사용했을 때
선언되어 있는
id에는 접근할
수 없다
=> Closure를 통해 모듈화를 할 수 있다.
22. Closure
6. Closure
- 생명주기가 끝난 변수(id)가 계속 참조 가능한 이유 :
중첩된 함수에 대한 참조가 전역 유효범위(uniqueId) 안에 저장되
어 있기 때문
- 전제 조건 :
바깥 함수(uniqueId)의 반환값으로 중첩된 함수(return의 함수)를
사용하거나 중첩된 함수를 객체의 프로퍼티로 저장
var uniqueId = (function(){
var id = 0;
return function(){
return id++;
}
})();