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

语法

Object.getPrototypeOf(object)

  1. var my_obj = Object.create({}, {
  2. getFoo: {
  3. value: function() { return this.foo; },
  4. enumerable: false
  5. }
  6. });
  7. my_obj.foo = 1;
  8. Object.defineProperty(my_obj, 'block' ,{
  9. value:520,
  10. writable:true,
  11. enumerable:true,
  12. });
  1. var my_obj = Object.create({}, {
  2. getFoo: {
  3. value: function() { return this.foo; },
  4. enumerable: true
  5. }
  6. });
  7. my_obj.foo = 1;
  8. Object.defineProperty(my_obj, 'block' ,{
  9. value:520,
  10. writable:true,
  11. enumerable:true,
  12. });
  13. var pt = Object.getPrototypeOf(my_obj)
  14. console.log(Object.entries(my_obj))
  15. console.log(my_obj.constructor)
  16. console.log(my_obj.prototype.constructor) //TypeError: Cannot read property 'constructor' of undefined
  17. //我们是通过 Object.create() 创建的并不会给我们初始化Object.constructor这个东西