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출력
파라미터와 함수를 추가로 넣을 수도 있다.