본문 바로가기

es 6

11. Array Object ECMA Script 5 부터 이미 Array 라는 빌트인 오브젝트가 존재했다. 그런데 이 Array Object 에 새로운 기능들이 많이 추가 됐으니... 자세한 내용은 아래의 URL 을 참고하기 바란다.참고 : http://www.ecma-international.org/ecma-262/6.0/#sec-array-objects 근데 솔직히 여기에 내용을 다 적지는 못하겠다.. ㅋㅋ읽을 엄두도 안날만큼의 양이라서 ㅜㅠ 그냥 눈에 보이는것, 그리고 영보 쌤 강의에서 배운것들만 몇개 정리해보겠다! Array.from let arrayLike = { 0: 'zero', 1: 'one', length:2}; let arrayObj = Array.from(arrayLike); console.log(Array.i.. 더보기
10. Object assign 자바스크립트에서 이런 코드를 작성해 본 적이 있는가?? let sports = {event: "축구", player: 11}; let dup = {}; dup = sports; sports.player = 55; console.log(dup.player); //55 출력 dup.event = '농구'; console.log(sports.event); //농구가 출력 //그래서 이런 처리를 해줘야 함.... 너무 귀츈귀츈... ㅜㅠㅜㅠ for( var key in sports ) { dup[key] = sports[key]; } assigning enumerable properties 는 copy 가 아니라 ref 되는 현상이다. 보통은 이를 막기 위해서 모든 properties 를 for 문을 돌려서 직.. 더보기
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.. 더보기
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.. 더보기