본문 바로가기

javascript 강좌

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 문을 돌려서 직.. 더보기
8. Enhanced Object ProPerties Property Shorthand let one =1, two = 2; let values = {one, two}; console.log(values); //Object // one:1 // two:2 선언한 variable 의 name 이 key 값으로 대체되는 것을 알 수 있다. Computed Property Names function quux() { return 'quux'; } let obj = { foo: "bar", [ "baz" + quux() ]: 42 } console.log(obj); //Object {foo: "bar", bazquux: 42} 출력 Object 의 Property Name 설정시 대괄호 ( [] ) 를 치고 그 안에 값을 적으면 그 값들이 미리 Computed 된 .. 더보기
7. destructuring 딱히 설명할 것이 없어서 샘플코드로만 대체하려 한다. 변수를 특정 구조에 맞게 작성하고, 그에 따른 구조에 맞게 값을 할당하면 그 모습 그대로 들어간다는 것을 보면 될듯하다. SampleArray Matching let values = [1,2,3]; let one, two; [one, two] = [values]; console.log(one+ ',' + two); //1, 2 가 출력 let three, four; [one, two, three, four] = [values]; console.log(one+ ',' + two+ ',' + three+ ',' + four); //1,2,3,undefined 가 출력 [one, two, [three, four]] = [1,2, [73, 74]]; [one.. 더보기
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.. 더보기