Skip to content

Latest commit

 

History

History
63 lines (42 loc) · 1.54 KB

File metadata and controls

63 lines (42 loc) · 1.54 KB
title slug
Object.getPrototypeOf()
Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf

{{JSRef}}

Object.getPrototypeOf() 静态方法返回指定对象的原型(即内部 [[Prototype]] 属性的值)。

{{EmbedInteractiveExample("pages/js/object-getprototypeof.html", "shorter")}}

语法

Object.getPrototypeOf(obj)

参数

  • obj
    • : 要返回其原型的对象。

返回值

给定对象的原型,可能是 null

示例

使用 getPrototypeOf

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

非对象强制类型转换

在 ES5 中,如果 obj 参数不是对象,则会抛出 {{jsxref("TypeError")}} 异常。在 ES2015 中,该参数将被强制转换为 {{jsxref("Object")}}。

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

规范

{{Specifications}}

浏览器兼容性

{{Compat}}

参见