자료구조

KoEunseo·2022년 9월 19일
0

algorithm

목록 보기
4/8

data structure: collections of values

ES2015 class syntax

생성자

class Student {
  constructor(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
}

인스턴스 생성

let firstStudent = new Student("Beak", "Seolgi");

인스턴스 메서드

greetingStudent(){
  return `Hello ${this.firstName} ${this.lastName}`;
}

클래스 메서드

클래스의 인스턴화 없이도 호출될 수 있으며 클래스 인스턴스를 통해서는 호출될 수 없다.

static EnrollingStudents(){
  return "Enrolling students"
}
firstStudent.EnrollStudent() //x
Student.EnrollStudent()      //o

여기서 this는 클래스로부터 생성된 인스턴스를 참조한다.

profile
주니어 플러터 개발자의 고군분투기

0개의 댓글