class Person{
name = 'Max' # property
call = () => {...} # method
}
const myPerson = new Person()
myPerson.call()
console.log(myPerson.name)
class Person extends Master
class Human {
constructor() {
this.gender = 'male';
}
printGender() {
console.log(this.gender);
}
}
class Person extends Human {
#다른 클래스를 확장하고 생성자를 실행하면 super키워드를 추가해야함
constructor() {
super(); # 상위클래스의 생성자 함수를 실행함
this.name = 'Max';
}
printMyname() {
console.log(this.name);
}
}
const person = new Person();
person.printMyname();
person.printGender();
ES6
constructor() {
this.myProperty = 'value'
}
myMethod() {...}
ES7
myProperty = 'value'
myMethod = () => {...}
생성자함수 필요 X
화살표 함수 -> this 키워드 사용하지 않아도 됨
class Human {
gender = 'male';
printGender = () => {
console.log(this.gender);
}
}
class Person extends Human {
name = 'Max';
gender = 'female';
printMyname = () => {
console.log(this.name);
}
}
const person = new Person();
person.printMyname();
person.printGender();