Files
2nd/10_Wiki/Topic_Programming/Topic_JavaScript/JavaScript_Classes.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

5.7 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
javascript-classes JavaScript Classes Frontend draft conceptual
ES6 classes
class syntax
constructor method
class methods
use strict
B 0.89 2026-06-23 2026-06-23
javascript
js
web
frontend
w3schools
classes
oop
es6
https://www.w3schools.com/js/js_classes.asp

JavaScript Classes

🎯 한 줄 통찰 (One-line insight)

A JavaScript class, introduced in ES6, is a template for objects (not an object itself), defined with the class keyword and a constructor() method that runs automatically on new. [S1]

🧠 핵심 개념 (Core concepts)

  • Classes are ES6 templates — a class is a template for JavaScript objects, defined with the class keyword and a constructor() method. [S1]
  • A class is not an object — it is a template from which objects are created. [S1]
  • The constructor runs automatically — the constructor method is called automatically when a new object is created with new. [S1]
  • Constructor rules — it must use the exact name constructor, executes automatically, and initializes properties. [S1]
  • Class methods are defined inside the class body and can take parameters. [S1]
  • Strict mode — classes require "strict mode" compliance (e.g. variables must be declared with const/let). [S1]

🧩 추출된 패턴 (Extracted patterns)

  • constructor + this initialization — assign incoming arguments to this.* in the constructor to set up object state. [S1]
  • Method computes from state — methods like age() derive values from the instance's own properties (e.g. this.year). [S1]
  • Pass external data as a parameter — when a method needs outside data (like the current year), pass it in as an argument rather than recomputing. [S1]

📖 세부 내용 (Details)

JavaScript Class Syntax ES6 introduced JavaScript Classes as templates for objects. The basic syntax uses the class keyword with a constructor() method: [S1]

class ClassName {
  constructor() { ... }
}

A concrete example: [S1]

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}

A JavaScript class is not an object. It is a template for JavaScript objects. [S1]

Using a Class Instantiate with new: [S1]

const myCar1 = new Car("Ford", 2014);
const myCar2 = new Car("Audi", 2019);

The constructor method is called automatically when a new object is created. [S1]

The Constructor Method The constructor must use the exact name constructor, executes automatically when objects are created, and initializes properties. [S1]

Class Methods A method computing the car's age from this.year: [S1]

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
  age() {
    const date = new Date();
    return date.getFullYear() - this.year;
  }
}

const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML =
"My car is " + myCar.age() + " years old.";

A method that accepts a parameter: [S1]

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
  age(x) {
    return x - this.year;
  }
}

const date = new Date();
let year = date.getFullYear();

const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML=
"My car is " + myCar.age(year) + " years old.";

"use strict" Classes require "strict mode" compliance — variables must be properly declared: [S1]

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
  age() {
    // date = new Date();  // This will not work
    const date = new Date(); // This will work
    return date.getFullYear() - this.year;
  }
}

🛠️ 적용 사례 (Applied in summary)

The Car class is the running applied example — defining name/year in the constructor, deriving age in a method (with and without a parameter), and demonstrating strict-mode variable declaration. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Define a class and instantiate it (language: JavaScript):

class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}
const myCar1 = new Car("Ford", 2014);

Add a method that uses instance state:

age() {
  const date = new Date();
  return date.getFullYear() - this.year;
}

⚖️ 모순 및 업데이트 (Contradictions & updates)

No contradictions found in the source.

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.89
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Classes" page (Astra wiki-curation, P-Reinforce v3.1 format).