Baseline Widely available *
static í¤ìëë í´ëì¤ì ì ì ë©ìë를 ì ìí©ëë¤.
ìëí´ ë³´ê¸°class ClassWithStaticMethod {
static staticProperty = "someValue";
static staticMethod() {
return "static method has been called.";
}
static {
console.log("Class static initialization block called");
}
}
console.log(ClassWithStaticMethod.staticProperty);
// Expected output: "someValue"
console.log(ClassWithStaticMethod.staticMethod());
// Expected output: "static method has been called."
문ë²
static methodName() { ... }ì¤ëª
ì ì ë©ìëë í´ëì¤ì ì¸ì¤í´ì¤ ìì´ í¸ì¶ì´ ê°ë¥íë©° í´ëì¤ê° ì¸ì¤í´ì¤íëë©´ í¸ì¶í ì ìë¤. ì ì ë©ìëë ì¢ ì¢ ì´í리ì¼ì´ì ì ì í¸ë¦¬í° í¨ì를 ë§ëëë° ì¬ì©ëë¤.
ì ì ë©ìëì í¸ì¶ ë¤ë¥¸ ì ì ë©ìëììì í¸ì¶ëì¼í í´ëì¤ ë´ì ë¤ë¥¸ ì ì ë©ìë ë´ìì ì ì ë©ìë를 í¸ì¶íë ê²½ì° í¤ìë this
를 ì¬ì©í ì ìë¤.
class StaticMethodCall {
static staticMethod() {
return "Static method has been called";
}
static anotherStaticMethod() {
return this.staticMethod() + " from another static method";
}
}
StaticMethodCall.staticMethod();
// 'Static method has been called'
StaticMethodCall.anotherStaticMethod();
// 'Static method has been called from another static method'
í´ëì¤ ìì±ì ë° ë¤ë¥¸ ë©ìëììì í¸ì¶
ì ì ë©ìëê° ë¹ì ì ë©ìëìì í¤ìëthis
를 ì¨ìë ì§ì ì ì¸ ì ê·¼ì í ì ìë¤. ë°ë¥¸ í¸ì¶ ë°©ë²ì í´ëì¤ ëª
ì¹ì ì°ê±°ë, ì¦ CLASSNAME.STATIC_METHOD_NAME()
ì ì´ì©íê±°ë í¹ì ê·¸ ë©ìë를 ìì±ìì í ìì±ì¼ë¡ ë¶ë¥´ë ê²ì¼ë¡, ì¦ constructor
: this.constructor.STATIC_METHOD_NAME()
를 ì´ì©íë¤.
class StaticMethodCall {
constructor() {
console.log(StaticMethodCall.staticMethod());
// 'static method has been called.'
console.log(this.constructor.staticMethod());
// 'static method has been called.'
}
static staticMethod() {
return "static method has been called.";
}
}
ìì
ìë ìì ë ì¬ë¬ê°ì§ ë´ì©ì ì¤ëª í©ëë¤.
class Triple {
static triple(n) {
n = n || 1; //ë¹í¸ì°ì°ì´ ìëì´ì¼ í©ëë¤.
return n * 3;
}
}
class BiggerTriple extends Triple {
static triple(n) {
return super.triple(n) * super.triple(n);
}
}
console.log(Triple.triple()); // 3
console.log(Triple.triple(6)); // 18
console.log(BiggerTriple.triple(3)); // 81
var tp = new Triple();
console.log(BiggerTriple.triple(3)); // 81 (ë¶ëª¨ì ì¸ì¤í´ì¤ì ìí¥ì ë°ì§ ììµëë¤.)
console.log(tp.triple()); // 'tp.tripleì í¨ìê° ìëëë¤.'.
console.log(tp.constructor.triple(4)); // 12
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ì°¸ê³
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4