zoukankan      html  css  js  c++  java
  • Object.create()和new Object()

    Object.create(null) 创建的对象是一个空对象,在该对象上没有继承 Object.prototype 原型链上的属性或者方法,例如:toString(), hasOwnProperty()等方法
    Object.create()方法接受两个参数:Object.create(obj,propertiesObject);
      obj:一个对象,应该是新创建的对象的原型。
      propertiesObject:可选.
    使用Object.create()是将对象继承到__proto__属性上
      var test = Object.create({x: 123, y: 345});
      console.log(test);
      console.log(test.x)
      console.log(test.__proto__.x)
      console.log(test.__proto__.x === test.x);

      var test1 = new Object({x: 123, y: 345});
      console.log(test1);
      console.log(test1.x);
      console.log(test1.__proto__.x)
      console.log(test1.__proto__.x === test1.x);

      var test2 = {x: 123, y: 345};
      console.log(test2);
      console.log(test2.x);
      console.log(test2.__proto__.x);
      console.log(test2.__proto__.x === test2.x)

  • 相关阅读:
    Python基础实例001:数字组合问题
    Python集合
    标量、向量、矩阵、张量
    re模块函数之search
    Python常用字符串操作
    Python基础之元组
    Bai, IEEE 2019
    词嵌入
    RNN 训练时梯度爆炸和梯度消失的理解
    OCR 综述
  • 原文地址:https://www.cnblogs.com/insignificant-malt/p/8558579.html
Copyright © 2011-2022 走看看