--- id: javascript-class-static title: "JavaScript Class Static" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["static methods", "static keyword", "class-level method", "Car.hello", "static members"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "classes", "static", "oop"] raw_sources: ["https://www.w3schools.com/js/js_class_static.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Class Static]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Static methods are defined with the `static` keyword on the class itself and can only be called on the class, not on its objects β€” pass an object in as a parameter if a static method needs instance data. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Static methods live on the class** β€” static class methods are defined on the class itself. [S1] - **Call on the class, not the object** β€” you cannot call a `static` method on an object, only on an object class. [S1] - **Use a parameter for instance data** β€” to use an object within a static method, send it as a parameter. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **`static` for class-level utilities** β€” declare methods with `static` when they belong to the class rather than to any single instance. [S1] - **Inject the instance** β€” when a static method needs object state, pass the object in (e.g. `Car.hello(myCar)`) since `this` will not be an instance. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Static Methods** Static class methods are defined on the class itself. You cannot call a `static` method on an object, only on an object class: [S1] ```javascript class Car { constructor(name) { this.name = name; } static hello() { return "Hello!!"; } } const myCar = new Car("Ford"); // You can call 'hello()' on the Car Class: document.getElementById("demo").innerHTML = Car.hello(); // But NOT on a Car Object: // document.getElementById("demo").innerHTML = myCar.hello(); // this will raise an error. ``` **Passing an Object to a Static Method** If you want to use an object inside a static method, you can send it as a parameter: [S1] ```javascript class Car { constructor(name) { this.name = name; } static hello(x) { return "Hello " + x.name; } } const myCar = new Car("Ford"); document.getElementById("demo").innerHTML = Car.hello(myCar); ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The `Car.hello()` examples are the canonical applied cases β€” one showing that the static method is callable only on the class, the other showing the object passed in as a parameter to access `x.name`. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Declare and call a static method on the class (language: JavaScript): ```javascript class Car { constructor(name) { this.name = name; } static hello() { return "Hello!!"; } } Car.hello(); // βœ… on the class // myCar.hello(); // ❌ on an object β†’ error ``` Pass an instance into a static method: ```javascript static hello(x) { return "Hello " + x.name; } Car.hello(myCar); ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Classes]], [[JavaScript Class Inheritance]], [[JavaScript Objects]], [[JavaScript Object Methods]] - **μ°Έμ‘° λ§₯락:** Extends JavaScript Classes with class-level (static) methods and their call-site restriction. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Class Static β€” https://www.w3schools.com/js/js_class_static.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Class Static" page (Astra wiki-curation, P-Reinforce v3.1 format).