Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Object.prototype.isPrototypeOf()

현재 번역은 완벽하지 않습니다. 한국어로 문서 번역에 동참해주세요.

Summary

isPrototypeOf() 메소드는 해당 객체가 다른 객체의 프로토타입 체인에 속한 객체인지 확인하기 위해 사용됩니다.

Note: isPrototypeOfinstanceof 연산자와 다릅니다. "object instanceof AFunction"표현식에서는 object의 프로토타입 체인을 AFunction 자체가 아니라 AFunction.prototype에 대해 확인을 합니다.

Syntax

prototypeObj.isPrototypeOf(obj)

Parameters

prototypeObj
객체는 그 객체 인자의 프로토타입 체인에 존재하는 각 연결에 대해 확인 받습니다. 
object
프로토타입 체인을 가지고 있는 객체가 검색될 것 입니다.

Description

isPrototypeOf 메소드는 또 다른 객체의 프로토타입 체인에 해당 객체가 존재하는지 여부를 확인할수 있습니다.

예를들어, 다음의 프로토타입체인을 고려해봅시다.

function Fee() {
  // ...
}

function Fi() {
  // ...
}
Fi.prototype = new Fee();

function Fo() {
  // ...
}
Fo.prototype = new Fi();

function Fum() {
  // ...
}
Fum.prototype = new Fo();

실행되고 나면 Fum 인스턴스의 프로토타입체인이 Fi의 프로토타입과 연결되어있는지를 확인할 필요가 있습니다. 다음과 같은 방법으로 확인할 수 있습니다:

var fum = new Fum();
// ...

if (Fi.prototype.isPrototypeOf(fum)) {
  // do something safe
}

이 메소드는 instanceof 연산자와 함께 특정 프로토타입으로부터 상속된 객체만 작동하게 하려는(예를 들어 특정 메소드나 속성이 객체에 있다는걸 보장하려는 때) 코드에서 특히 쓸모가 많다.

Specifications

Specification Status Comment
ECMAScript 3rd Edition. Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
The definition of 'Object.prototype.hasOwnProperty' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object.prototype.hasOwnProperty' in that specification.
Standard  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: BrandenYoon, bsidesoft
 최종 변경: BrandenYoon,