| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks | [Back] [Original] |
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. Its been available across browsers since 2023 3.
, try...catch .
. . (C++ "friend" )
class ClassWithStaticInitializationBlock {
static staticProperty1 = "Property 1";
static staticProperty2;
static {
this.staticProperty2 = "Property 2";
}
}
console.log(ClassWithStaticInitializationBlock.staticProperty1);
// Expected output: "Property 1"
console.log(ClassWithStaticInitializationBlock.staticProperty2);
// Expected output: "Property 2"
static { /* */ }
.
static {} var, function, const let var .
var y = " y";
class A {
static field = " y";
static {
var y = this.field;
}
}
// var
console.log(y);
// > ' y'
this .
super.<property> super .
super() .
lexical scope .
. ( )
. .
class MyClass {
static field1 = console.log("1 ");
static {
console.log("1 ");
}
static field2 = console.log("2 ");
static {
console.log("2 ");
}
}
/*
> "1 "
> "1 "
> "2 "
> "2 "
*/
super .
this .
.
class A {
static field = " ";
static {
console.log(this.field);
}
}
super.property static super .
.
class A {
static fieldA = "A.fieldA";
}
class B extends A {
static {
console.log(super.fieldA);
// 'A.fieldA'
}
}
. (v8.dev blog ).
let getDPrivateField;
class D {
#privateField;
constructor(v) {
this.#privateField = v;
}
static {
getDPrivateField = (d) => d.#privateField;
}
}
getDPrivateField(new D("private"));
// > private
ES13 .
.
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # prod-ClassStaticBlock |
super()This page was last modified on 2025 2 11 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |