MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Object.getPrototypeOf()

Object.getPrototypeOf() 回傳指定物件的原型,換句話說,就是取得該物件的 [[Prototype]] 屬性的值).

表達式

Object.getPrototypeOf(obj)

參數

obj
欲取得原型的物件。

範例

var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true

備註

如果 obj 參數在 ES5 並不是物件時會拋出 TypeError 例外,同樣狀況在 ES6 時該參數將會被強制轉換成 Object

Object.getPrototypeOf("foo");
// TypeError: "foo" is not an object (ES5 code)
Object.getPrototypeOf("foo");
// String.prototype                  (ES6 code)

規範

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

瀏覽器相容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 3.5 (1.9.1) 9 12.10 5
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?

Opera 註

雖然舊版的 Opera 並不支援 Object.getPrototypeOf(),但是 Opera 從 Opera 10.50 支援非標準的 __proto__ 屬性。

參見

文件標籤與貢獻者

 此頁面的貢獻者: Shiyou, alk03073135
 最近更新: Shiyou,