ES6 문법 03 (23.05.15)

Jane·2023년 5월 15일
0

IT 수업 정리

목록 보기
123/124

1. 객체 리터럴 개선

        var name = "백두산";
        var elevation = 2744; // 높이(단위: 미터)

        var funHike = { name, elevation };

        console.log(funHike) // {name: "백두산", elavation: 2744}

{name: '백두산', elevation: 2744}
elevation: 2744
name: "백두산"
[[Prototype]]: Object
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
defineGetter: ƒ defineGetter()
defineSetter: ƒ defineSetter()
lookupGetter: ƒ lookupGetter()
lookupSetter: ƒ lookupSetter()
proto: (...)
get proto: ƒ proto()
set proto: ƒ proto()


  • EL 문법도 적용할 수 있다.
        var name = "백두산";
        var elevation = 2744;
        var print = function () {
            console.log(`${this.name}의 높이는 ${this.elevation}m 입니다.`);
        }
        var funHike = { name, elevation, print }

        funHike.print() //	백두산의 높이는 2744m 입니다.

백두산의 높이는 2744m 입니다.

2. this

  • this : JavaScript에서는 호출의 개념
        function myFun() {
            return this; // window
        }

        console.log(myFun());


         
      var num = 0;
      
      function addNum() {
        this.num = 100;
        num++;
        
        console.log(num); // 101
        console.log(window.num); // 101
        console.log(num === window.num); // true
      }
 
     addNum();
profile
velog, GitHub, Notion 등에 작업물을 정리하고 있습니다.

0개의 댓글