Files
2nd/10_Wiki/Topic_JavaScript/JavaScript_Classes.md
T
koriweb 9609c04755 docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)
W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더).
- Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외)
- Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체)
- Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속)
각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 19:21:18 +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).