instanceOf 연산자(operator)
instanceOf 연산자는 생성자의 프로토타입 속성이 객체의 프로토타입 체인에 존재하는지 판별하여 true 나 false를 뱉는다.
class Goodcoder {
constructor(age, lang, address) {
this.age = age;
this.lang = lang;
this.address = address;
}
}
const noran = new Goodcoder(20,'Java','Seoul');
console.log(noran instanceof Goodcoder); //true
console.log(paran instanceof Goodcoder); //Uncaught ReferenceError: paran is not defined
출처 : 드림코딩 https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko
'🟨 JavaScript > 개념' 카테고리의 다른 글
| [mdn, 드림코딩 외] 객체(Object)와 프로퍼티(property) (3) : computed properties (0) | 2022.05.31 |
|---|---|
| [mdn, 드림코딩 외] 객체(Object)와 프로퍼티(property) (2) : 생성/수정과 cloning (0) | 2022.05.31 |
| [mdn, 드림코딩 외] 객체지향 (4) : 클래스의 상속 (sub classing) (0) | 2022.05.25 |
| [mdn, 드림코딩 외] 객체지향 (3) : 정적 속성과 메소드(static properties and methods) (0) | 2022.05.04 |
| [mdn, 드림코딩 외] 객체지향 (2) : 객체(object)와 getter and setter (0) | 2022.05.04 |