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>
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
---
|
||||
id: javascript-object-constructors
|
||||
title: "JavaScript Object Constructors"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["Object constructor function", "constructor function", "new keyword", "Person constructor", "prototype property"]
|
||||
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", "objects", "constructors", "prototype"]
|
||||
raw_sources: ["https://www.w3schools.com/js/js_object_constructors.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[JavaScript Object Constructors]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
A constructor function is a reusable "object type" blueprint: call it with `new` to stamp out many objects of the same kind, where `this` becomes each new object. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Constructor functions are object blueprints** — when you need many objects of the same type, define a constructor function and create instances with the `new` keyword. [S1]
|
||||
- **Naming convention** — it is considered good practice to name constructor functions with an upper-case first letter (e.g. `Person`). [S1]
|
||||
- **`this` inside a constructor** — `this` has no value of its own; it becomes the new object being created when the function is invoked with `new`. [S1]
|
||||
- **Prototype changes affect all instances** — a property or method added to `Constructor.prototype` is shared by every object created from that constructor, whereas a property added to one object affects only that object. [S1]
|
||||
- **Use literals over built-in constructors** — JavaScript has built-in constructors (`new Object()`, `new Array()`, etc.), but the recommended best practice is to use the literal forms instead. [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **Capitalized constructor + `new`** — define `function Person(...) { this.x = ... }` and instantiate with `const p = new Person(...)`. [S1]
|
||||
- **Default property in the constructor** — assign a constant property inside the constructor body (`this.nationality = "English";`) so every instance gets it. [S1]
|
||||
- **Per-object vs. shared** — `obj.prop = value` adds to one object; `Constructor.prototype.prop = value` adds to all. [S1]
|
||||
- **Method as a property** — attach a function expression to `this` (`this.fullName = function() {...}`) to give instances a method. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Object Type (constructor function)**
|
||||
When you want to create many objects of the same type, you can use an object constructor function. It is considered good practice to name constructor functions with an upper-case first letter. The example below defines a `Person` object type: [S1]
|
||||
```javascript
|
||||
function Person(first, last, age, eye) {
|
||||
this.firstName = first;
|
||||
this.lastName = last;
|
||||
this.age = age;
|
||||
this.eyeColor = eye;
|
||||
}
|
||||
```
|
||||
|
||||
**Creating objects with `new`**
|
||||
Once the object type exists, you create new objects of that type with the `new` keyword: [S1]
|
||||
```javascript
|
||||
const myFather = new Person("John", "Doe", 50, "blue");
|
||||
const myMother = new Person("Sally", "Rally", 48, "green");
|
||||
const mySister = new Person("Anna", "Rally", 18, "green");
|
||||
const mySelf = new Person("Johnny", "Rally", 22, "green");
|
||||
```
|
||||
|
||||
**Property Default Values**
|
||||
A value assigned to a property inside the constructor becomes a default value for all objects created from it: [S1]
|
||||
```javascript
|
||||
function Person(first, last, age, eyecolor) {
|
||||
this.firstName = first;
|
||||
this.lastName = last;
|
||||
this.age = age;
|
||||
this.eyeColor = eyecolor;
|
||||
this.nationality = "English";
|
||||
}
|
||||
```
|
||||
|
||||
**Adding a Property to an Object**
|
||||
Adding a property to a created object is easy, but it is added only to that single object — not to other objects of the same type: [S1]
|
||||
```javascript
|
||||
myFather.nationality = "English";
|
||||
```
|
||||
|
||||
**Adding a Property via Prototype**
|
||||
Adding a property to the constructor's prototype adds it to all objects created from the constructor: [S1]
|
||||
```javascript
|
||||
Person.prototype.nationality = "English";
|
||||
```
|
||||
|
||||
**Constructor Method**
|
||||
A method is a function defined as a property of the object. Methods can be defined inside the constructor: [S1]
|
||||
```javascript
|
||||
function Person(first, last, age, eyecolor) {
|
||||
this.firstName = first;
|
||||
this.lastName = last;
|
||||
this.age = age;
|
||||
this.eyeColor = eyecolor;
|
||||
this.fullName = function() {
|
||||
return this.firstName + " " + this.lastName;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
**Built-in JavaScript Constructors**
|
||||
JavaScript has built-in constructors for native objects: [S1]
|
||||
```javascript
|
||||
new Object(); // A new Object object
|
||||
new Array(); // A new Array object
|
||||
new Map(); // A new Map object
|
||||
new Set(); // A new Set object
|
||||
new Date(); // A new Date object
|
||||
new RegExp(); // A new RegExp object
|
||||
new Function(); // A new Function object
|
||||
```
|
||||
Best practice: there is no reason to use these built-in constructors. Use the literal equivalents instead — `{}` for `new Object()`, `[]` for `new Array()`, `/()/` for `new RegExp()`, and `function (){}` for `new Function()`. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's `Person` examples are the canonical applied use: defining an object type once and creating multiple instances (`myFather`, `myMother`, `mySister`, `mySelf`) from it, then extending them with default properties, prototype properties, and methods. No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Define a constructor and instantiate (language: JavaScript):
|
||||
```javascript
|
||||
function Person(first, last, age, eye) {
|
||||
this.firstName = first;
|
||||
this.lastName = last;
|
||||
this.age = age;
|
||||
this.eyeColor = eye;
|
||||
}
|
||||
const myFather = new Person("John", "Doe", 50, "blue");
|
||||
```
|
||||
Share across all instances via prototype:
|
||||
```javascript
|
||||
Person.prototype.nationality = "English";
|
||||
```
|
||||
Add a method:
|
||||
```javascript
|
||||
this.fullName = function() {
|
||||
return this.firstName + " " + this.lastName;
|
||||
};
|
||||
```
|
||||
|
||||
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
|
||||
- **Constructor vs. object literal** — use a constructor function when you need *many* objects of the same type; for a one-off object, a literal `{}` is simpler. [S1]
|
||||
- **Per-object property vs. prototype property** — add to the object directly for an instance-specific value; add to the prototype to share across all instances. [S1]
|
||||
- **Built-in constructor vs. literal** — prefer literals (`{}`, `[]`, `/()/`, `function(){}`) over `new Object()`, `new Array()`, etc. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (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 Objects]], [[JavaScript Object Properties]], [[JavaScript Object Methods]], [[JavaScript Object Prototypes]]
|
||||
- **참조 맥락:** Referenced whenever you need a reusable object template instead of a single object literal.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — JavaScript Object Constructors — https://www.w3schools.com/js/js_object_constructors.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Object Constructors" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user