static1 JavaScript 기초(29)_클래스(4) static 1. static 변수, 함수 : 객체가 아닌, 클래스의 변수와 함수 다음의 코드를 보자. class A { static age = 31; static hello(){ console.log(A.age); } } console.log(A); console.log(A.age); A.hello(); [Running] [class A] { age: 31 } 31 31 클래스 A를 출력했을 때, [] 안에 클래스 이름이 나오며 {} 안에는 변수와 값이 출력된다. A.age로 접근하여 출력했을 때도 31이 정상 출력되며 A.hello()로 hello() 함수에 접근하여도 31이 정상 출력된다. 그렇다면 위 코드에서 'static'을 제거하면 어떻게 될까? class B { age = 31; hello(){ cons.. 2021. 10. 26. 이전 1 다음