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()

この翻訳は不完全です。英語から この記事を翻訳 してください。

概要

オブジェクトが別のオブジェクトのプロトタイプチェーンに存在するかどうかを判定します。

構文

prototype.isPrototypeOf(object)

引数

prototype
引数に指定したオブジェクトのプロトタイプチェーン内の各リンクに対してテストするオブジェクト
注記: isPrototypeOfinstanceof 演算子 とは異なるものです。In the expression object instanceof AFunction, the object prototype chain is checked against AFunction.prototype, not against AFunction itself
object
プロトタイプチェーンの検索対象

説明

isPrototypeOf を用いると、オブジェクトが別のオブジェクト内のプロトタイプチェーンに存在するかどうかをチェックする事ができます。

例えば、次の様なプロトタイプチェーンがあったとします。

function Fee() {
  // . . .
}

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

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

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

Later on down the road, if you instantiate Fum and need to check if Fi's prototype exists within the Fum prototype chain, you could do this:

var fum = new Fum();
. . .

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

This, along with the instanceof operator particularly comes in handy if you have code that can only function when dealing with objects descended from a specific prototype chain, e.g., to guarantee that certain methods or properties will be present on that object.

関連情報

ドキュメントのタグと貢献者

 このページの貢献者: teoli, ethertank, Mgjbot, Potappo, Yuichirou
 最終更新者: teoli,