Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021년 7월.
class 의 속성(property)들은 기본적으로 public 하며 class 외부에서 읽히고 수정될 수 있다. 하지만, ES2019 에서는 해쉬 # prefix 를 추가해 private class 필드를 선언할 수 있게 되었다.
private 필드는 class 선언문 내부의 class 생성자(class constructor)에서 접근이 가능하다.
static 메소드에서만 static 변수들을 호출할 수 있다는 제약은 그대로 유지된다.
Private static 필드는 class evaluation 시 class 생성자(class constructor)에 추가된다.
Private static 필드는 해당 필드를 선언한 class 에서만 접근할 수 있다.
이는 this 를 사용함에 있어 예상치 못한 동작을 야기할 수 있다.
private 인스턴스 필드는 # 이름 ('해쉬 이름' 으로 발음), 즉 # prefix 를 가진 식별자로 선언된다. # 은 그 이름 자체의 일부이며 선언과 접근 시에 모두 사용된다.
캡슐화(encapsulation) 는 언어로부터 강제된다(enforced by the language). 즉, scope 밖에서 # 이름에 접근하는 것은 syntax error 이다.
private static 메소드는 public static 메소드처럼 인스턴스가 아닌 class 로부터 호출된다. 그리고 private static 필드처럼 class 선언문 내부에서만 접근 가능하다.
이는 this 를 사용할 때 예상치 못한 동작을 발생시킬 수 있다. (이는 this binding rule 이 적용되기 때문이다.) 다음 예시에서 Derived.publicStaticMethod2() 를 호출할 때, this 는 class Derived (Base 가 아니라) 를 가리킨다.
private 인스턴스 메소드는 private 인스턴스 필드와는 다르게 class 인스턴스로부터 접근 가능하다.
private 인스턴스 메소드는 generator, async 그리고 async generator 함수가 될 수 있다. private getter 와 setter 또한 가능하다:
| ECMAScript® 2027 Language Specification # prod-PrivateIdentifier |
| ECMAScript® 2027 Language Specification # prod-00OK517S |
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 7월 9일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.