Object.getPrototypeOf()
Object.getPrototypeOf()
静态方法返回指定对象的原型(即内部 [[Prototype]]
属性的值)。
¥The Object.getPrototypeOf()
static method returns the prototype
(i.e. the value of the internal [[Prototype]]
property) of the specified
object.
Try it
语法
参数
返回值
示例
使用 getPrototypeOf
非对象强制
¥Non-object coercion
在 ES5 中,如果 obj
参数不是对象,则会抛出 TypeError
异常。在 ES2015 中,该参数将被强制为 Object
。
¥In ES5, it will throw a TypeError
exception if the obj
parameter isn't an object. In ES2015, the parameter will be coerced to an
Object
.
js
Object.getPrototypeOf("foo");
// TypeError: "foo" is not an object (ES5 code)
Object.getPrototypeOf("foo");
// String.prototype (ES2015 code)
规范
Specification |
---|
ECMAScript Language Specification # sec-object.getprototypeof |
浏览器兼容性
BCD tables only load in the browser