Object.getPrototypeOf(obj)
- 返回指定对象的原型(内部
[[Prototype]]
属性的值)。 - obj:要返回其原型的对象。
- 返回值:给定对象的原型。如果没有继承属性,则返回 null 。
var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true
var reg = /a/;
Object.getPrototypeOf(reg) === RegExp.prototype; // true
Object.getPrototypeOf(new Date()) === Date.prototype // true
一些注意点
console.log(Object.getPrototypeOf(Object) === Function.prototype)
console.log(Object.getPrototypeOf(Function) === Function.prototype)
console.log(Object.getPrototypeOf(Date) === Function.prototype)
console.log(Object.getPrototypeOf(Object()) === Object.prototype)
console.log(Object.getPrototypeOf(Function()) === Function.prototype)
console.log(Object.getPrototypeOf(Date()) === String.prototype)
console.log(Object.getPrototypeOf(new Object()) === Object.prototype)
console.log(Object.getPrototypeOf({}) === Object.prototype)
console.log(Object.getPrototypeOf(new Function()) === Function.prototype)
console.log(Object.getPrototypeOf(new Date()) === Date.prototype)
console.log({} == new Object())
标签:Function,obj,log,Object,getPrototypeOf,console,prototype From: https://blog.51cto.com/u_13028258/5754005