From ee778d6eea54935fd05022e0ba8c49456003381a Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:48:24 +0100 Subject: unslug ko: move --- .../index.html | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 files/ko/orphaned/web/javascript/differential_inheritance_in_javascript/index.html (limited to 'files/ko/orphaned/web/javascript/differential_inheritance_in_javascript') diff --git a/files/ko/orphaned/web/javascript/differential_inheritance_in_javascript/index.html b/files/ko/orphaned/web/javascript/differential_inheritance_in_javascript/index.html new file mode 100644 index 0000000000..70fd4256c3 --- /dev/null +++ b/files/ko/orphaned/web/javascript/differential_inheritance_in_javascript/index.html @@ -0,0 +1,63 @@ +--- +title: Differential inheritance in JavaScript +slug: Web/JavaScript/Differential_inheritance_in_JavaScript +translation_of: Web/JavaScript/Differential_inheritance_in_JavaScript +--- +

Introduction

+ +

차등 상속(Differential Inheritance)은 자바 스크립트와 같은 프로토 타입 기반 프로그래밍 언어에서 사용되는 일반적인 상속 모델입니다. 대부분의 객체는 다른 일반적인 객체에서 파생되고 몇 가지 작은 측면에서만 차이가 있다는 원칙에 따라 동작합니다. 일반적으로 객체가 다른 다른 객체에 대한 포인터 목록을 내부적으로 유지합니다.

+ +

Example

+ + + +

다음 코드는 개체를 "상속"하는 간단한 메서드 예제입니다.

+ +
Object.prototype.inherit = function(){
+  // Create a new object with this as its prototype
+  var p = Object.create(this);
+
+  /* actually not necessary:
+  // Apply the constructor on the new object
+  this.constructor.apply(p, arguments);
+  */
+
+  return p;
+};
+
+ +

상속(inherit)을 사용하면 일반 프로토 타입에서보다 구체적인 개체를 간단히 파생시킬 수 있습니다. 다음은 상속 방법 및 차등 상속을 사용하여 점점 더 구체적인 객체를 구성하는 간단한 예입니다.

+ +
var root = {}; // Could be any object with any prototype object
+
+var record = root.inherit();
+record.toString = function(){ return "a Record"; };
+
+var person = root.inherit();
+person.firstName = false;
+person.lastName = false;
+person.toString = function(){
+    if (this.firstName) {
+        if (this.lastName) {
+            return this.firstName + " " + this.lastName;
+        } else {
+            return this.firstName;
+        }
+    } else if (this.lastName) {
+        return this.lastName;
+    } else {
+        return "a Person";
+    }
+};
+
+JoePerson = person.inherit();
+JoePerson.firstName = "Joe";
+alert( JoePerson.toString() );
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf