JS중급_class

Adrian·2022년 3월 13일
0
post-thumbnail

▶️ ES6 class 문법

  class Parents {
      constructor(){
          this.name = "kim"
          this.sayHi = function(){
            console.log('hello')
                                 }
      }
  }

  var child = new Parents();

ES6에 새로 추가된 신문법인 class 이다. function Name() 이렇게 쓰던 문법과 유사하다.

  class Parents {
      constructor(){
          this.name = "kim"
      }
      sayHi(){
      console.log('hello')
      }
  }

  var child = new Parents();
  Object.getPrototypeOf();// 상속받은 부모prototype출력 

함수는 이렇게 prototype 안에 넣어 줄수도 있다.

  class Parents {
      constructor(name, age){
          this.name = name;
         this.age = age;
      }
      sayHi(){
      console.log('hello')
      }
      sayHello(){
      console.log('Hi')
      }
  }

  var child = new Parents();
  Object.getPrototypeOf();// 상속받은 부모prototype출력 

파라미터와 함수를 추가로 넣을 수도 있다.


profile
관조, 사유, 끈기

0개의 댓글