본문 바로가기

es 2015

9. for of 아... 너무 졸립다... ㅜㅠ그래서 오늘은 진짜 짧게 쓸 주제 하나 찾아서 쓰려한다. 그 주제는 바로 for-of사실 처음부터 그냥 쓰려고 했으면 쓰기 어렵고, 길게 써야 하나우리는 사실 이미 http://ggoals.tistory.com/32 에서 iterable protocol즉, iterable object 에 대해서 배운적이 있다. for-of 는 iterable object 에 대해서만 반복문을 실행시켜준다. Array-like 에서 설명했던 코드를 다시 가져와보면 let values = {0: 'aaa', 1: 'bbb', length: 2}; for( var key in values) { console.log( key + ": " + values[key]); } for(var k = 0; .. 더보기
6. Array-like 빌트인 오브젝트인 Array 의 경우 아래와 같은 4가지 특징을 가지고 있다. 1. length property 는 list 에 element 가 추가 될 때마다 자동으로 업데이트 된다. ( The length property is automatically updated as new elements are added to the list. ) 2. length 를 줄이면 array 도 줄어든다. ( Setting length to a smaller value truncates the array. ) 3. Arrays 들은 Array.prototype 으로 부터 method 를 상속 받는다. 이건 당연한 개념이겠지만 buildt in Array object 가 생성될때 Array 의 prototype 의 .. 더보기
5. rest Aggregation of remaining arguments into single parameter of variadic functions.4장의 spread 가 펼쳐주는거라면 이건 묶어주는 느낌으로 보면 어떨까 싶다 :)Syntaxfunction(param, paramN, ...rest ) SampleES6 에서 rest 를 쓰면 function f (x, y, ...a) { return (x + y) * a.length } f(1, 2, "hello", true, 7) === 9 ES5 에서 rest 를 그대로 구현하면 function f (x, y) { var a = Array.prototype.slice.call(arguments, 2); return (x + y) * a.length; }; f.. 더보기
4. spread 3 장에서 배웠던 iterable collection ( object ) 를 왜 배웠나.뒤로 가면 계속 나오겠지만 iterable 의 의미가 얼마나 많이 쓰이는 가를 볼 수 있을 것이다. Syntax [...iterable]이터러블 오브젝트를 하나씩 전개[...iterable]spec 에서 spread operator 로 표기하지는 않았음[] 안에 spread 대상 배열 작성 Sample let two =[21, 22]; let five = [51, 52]; let one = [11, ...two, 12, ...five]; console.log(one); // [11,21,22,12,51,52] 가 출력 console.log(one.length); // 6 이 출력 JS Bin on jsbin.com S.. 더보기
3. iterable protocol 미리 설명하기에 앞서 +_+Symbol 과 Destructuring 은 다음에 다루도록 하겠다.아래 나오는 것중 Symbol.iterator 에서의 Symbol은 뭐지?? 라는 생각은 하지 말아주시길... ㅋ그리고 Destructuring 은 간단하게만 설명하면 let [a, b] = [1,2] console.log(a); //1 이 출력됌 console.log(b); //2 가 출력됌 자 그럼 이제 설명 시작!! iterable protocol 이란? The iterable protocol allows JavaScript objects to define or customize their iteration behavior, such as what values are looped over in a for... 더보기
2. arrow Lambda란?The term lambda function may refer to:In mathematics:Dirichlet lambda function λ(s) = (1 – 2−s)ζ(s) where ζ is the Riemann zeta function;Liouville function λ(n) = (–1)Ω(n);Mangoldt function Λ(n) = log p if n is a positive power of the prime p;Modular lambda function;In computing:Lambda calculus in computer science;Anonymous function in programming.출처 : https://en.wikipedia.org/wiki/Lambd.. 더보기
1. let, const let기존의 es5 에서 scope 은 function 단위였다. 아래의 예제를 보자 if(true) { var test = 1; } console.log(test); JS Bin on jsbin.com test 변수값이 block {} 안에 쓰여졌음에도 불구하고 console 에 정확히 찍힌다! 기존의 java, C#, 등등의 언어에 익숙한 사람이라면 ( block scope 을 사용하는 언어에 익숙한 사람이라면 ) 지금 이 상황이 당황스러울 수 있다 +_+ 나도 첨엔 그랬으니;;; ex. 가장 당황스러웠던 상황 아래를 보면 결과가 1,2,3, 이 찍힐거라 예상되지만 실제로는 그렇지 않다. 왜냐면 var i 는 function 안에 scope 이기 때문에 for 문이 3번 돌면 3이 되어 있고 setT.. 더보기