You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/09-classes/06-instanceof/article.md
+8-21Lines changed: 8 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,7 @@
2
2
3
3
`instanceof` 연산자를 사용하면 객체가 특정 클래스에 속하는지 아닌지를 확인할 수 있습니다. `instanceof`는 상속 관계도 확인해줍니다.
4
4
5
-
<<<<<<< HEAD
6
-
확인 기능은 다양한 곳에서 쓰이는데, 이번 챕터에선 `instanceof`를 사용해 인수의 타입에 따라 이를 다르게 처리하는 *다형적인(polymorphic)* 함수를 만드는데 사용해보겠습니다.
7
-
=======
8
-
Such a check may be necessary in many cases. For example, it can be used for building a *polymorphic* function, the one that treats arguments differently depending on their type.
9
-
>>>>>>> upstream/master
5
+
확인 기능은 다양한 곳에서 쓰이는데, 예를 들어 `instanceof`를 사용하면 인수의 타입에 따라 이를 다르게 처리하는 *다형적인(polymorphic)* 함수를 만들 수 있습니다.
2. 그런데, 대부분의 클래스엔 `Symbol.hasInstance`가 구현되어있지 않습니다. 이럴 땐 일반적인 로직이 사용됩니다. `obj instanceOf Class`는 `Class.prototype`이 `obj` 프로토타입 체인 상의 프로토타입 중 하나와 일치하는지 확인합니다.
82
-
=======
83
-
2. Most classes do not have `Symbol.hasInstance`. In that case, the standard logic is used:`obj instanceof Class` checks whether `Class.prototype` is equal to one of the prototypes in the `obj` prototype chain.
84
-
>>>>>>> upstream/master
71
+
2. 그런데 대부분의 클래스에는 `Symbol.hasInstance`가 구현되어 있지 않습니다. 이 경우 일반적인 로직이 사용됩니다. `obj instanceof Class`는 `Class.prototype`이 `obj` 프로토타입 체인 상의 프로토타입 중 하나와 일치하는지 확인합니다.
이렇게 `[object Object]`가 되는 이유는 `toString`의 구현방식 때문입니다. 그런데 `toString`엔 `toString`을 더 강력하게 만들어주는 기능이 숨겨져 있습니다. `toString`의 숨겨진 기능을 사용하면 확장 `typeof`, `instanceof`의 대안을 만들 수 있습니다.
138
+
이렇게 `[object Object]`가 되는 이유는 `toString`의 구현 방식 때문입니다. 그런데 `toString`엔 `toString`을 더 강력하게 만들어주는 기능이 숨겨져 있습니다. `toString`의 숨겨진 기능을 사용하면 확장 `typeof`, `instanceof`의 대안을 만들 수 있습니다.
152
139
153
140
아직 감이 안 잡히시겠지만, 구체적으로 설명하겠습니다.
154
141
@@ -159,7 +146,7 @@ alert(obj.toString()); // 같은 결과가 출력됨
0 commit comments