mozilla

Revision 343207 of Object.prototype.isPrototypeOf()

  • リビジョンの URL スラグ: JavaScript/Reference/Global_Objects/Object/isPrototypeOf
  • リビジョンのタイトル: Object.isPrototypeOf
  • リビジョンの ID: 343207
  • 作成日:
  • 作成者: ethertank
  • 現行リビジョン いいえ
  • コメント

このリビジョンの内容

概要

Tests for an object in another object's prototype chain.

Object オブジェクトのメソッド
実装されたバージョン JavaScript ?
ECMAScript エディション ECMAScript 3rd Edition

構文

prototype.isPrototypeOf(object)

引数

prototype
an object to be tested against each link in the prototype chain of the object argument
Notes: isPrototypeOf differs from instanceof operator. In the expression object instanceof AFunction, the object prototype chain is checked against AFunction.prototype, not against AFunction itself
object
the object whose prototype chain will be searched

説明

isPrototypeOf allows you to check whether or not an object exists within another object's prototype chain.

For example, consider the following prototype chain:

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.

関連情報

このリビジョンのソースコード

<h2 id="Summary" name="Summary">概要</h2>
<p>Tests for an object in another object's prototype chain.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2"><a href="/ja/docs/JavaScript/Reference/Global_Objects/Object" title="JavaScript/Reference/Global_Objects/Object"><code>Object</code></a> オブジェクトのメソッド</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>実装されたバージョン</td>
      <td>JavaScript ?</td>
    </tr>
    <tr>
      <td>ECMAScript エディション</td>
      <td>ECMAScript 3rd Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox">
<code><em>prototype</em>.isPrototypeOf(<em>object</em>)</code></pre>
<h3 id="Parameters" name="Parameters">引数</h3>
<dl>
  <dt>
    prototype</dt>
  <dd>
    an object to be tested against each link in the prototype chain of the <strong>object</strong> argument
    <div class="note">
      <em>Notes:</em> <code>isPrototypeOf</code> differs from <a href="/ja/docs/JavaScript/Reference/Operators/Special_Operators/instanceof_Operator">instanceof operator</a>. In the expression <code>object instanceof AFunction</code>, the <code>object</code> prototype chain is checked against <code>AFunction.prototype</code>, not against <code>AFunction</code> itself</div>
  </dd>
  <dt>
    object</dt>
  <dd>
    the object whose prototype chain will be searched</dd>
</dl>
<h2 id="Description" name="Description">説明</h2>
<p><code>isPrototypeOf</code> allows you to check whether or not an object exists within another object's prototype chain.</p>
<p>For example, consider the following prototype chain:</p>
<pre class="brush: js">
function Fee() {
  // . . .
}

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

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

function Fum() {
  // . . .
}
Fum.prototype = new Fo();</pre>
<p>Later on down the road, if you instantiate <code>Fum</code> and need to check if <code>Fi</code>'s prototype exists within the <code>Fum</code> prototype chain, you could do this:</p>
<pre class="brush: js">
var fum = new Fum();
. . .

if (Fi.prototype.isPrototypeOf(fum)) {
  // do something safe
}</pre>
<p>This, along with the <code>instanceof</code> 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.</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
  <li><a href="/ja/docs/JavaScript/Reference/Operators/instanceof" title="JavaScript/Reference/Operators/Special_Operators/instanceof_Operator">instanceof</a></li>
  <li><a href="/ja/docs/JavaScript/Reference/Global_Objects/Object/GetPrototypeOf" title="JavaScript/Reference/Global Objects/Object/GetPrototypeOf">getProtoypeOf</a></li>
</ul>
このリビジョンへ戻す