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)
转载于:https://www.cnblogs.com/insignificant-malt/p/8558579.html
Object.create()和new Object()相关推荐
- Object.create()和new object()和{}的区别
Object.create() 详细文档: Object.create() new Object() 和new操作符相关:new {} 字面量申明 列如 let NewObj03 = {n ...
- Object.create()和new object()区别
Object.create和new object区别 Object.create() proto propertiesObject Object.create(null) Object.create( ...
- 原生js实现Object.assign和Object.create
Object.assign(target,-sources) Object.assign(target,-source)方法用于将所有可枚举的属性的值从一个或多个源对象复制到目标对象.它将返回目标对象 ...
- object.create()
语法: Object.create(proto, [propertiesObject]) //方法创建一个新对象,使用现有的对象来提供新创建的对象的proto. 参数: proto : 必须.表示新建 ...
- 关于Object.create()与原型链的面试题?
原文地址 https://segmentfault.com/q/1010000004670616?utm_source=weekly&utm_medium=email&utm_camp ...
- Object.create(..)和new(..)的内部实现
Object.create() 经常会有这样的疑问?Object.create()到底做了什么工作? 像这样两行代码有什么不同? var obj ={a: 1} var b = obj var c = ...
- js-new、object.create、bind的模拟实现【转载备忘】
//创建Person构造函数,参数为name,age function Person(name,age){this.name = name;this.age = age; }function _new ...
- Object.create()和Object.assign()
一.Object.create() 该方法用于创建一个新对象,并为其指定原型对象和属性. 语法:Object.create(prototype,description); proto:(必须),表示新 ...
- Object.create()方法
Object.create()方法创建一个新对象,使用现有的对象来提供新创建的对象的proto. 语法:Object.create(proto, [propertiesObject]) - proto ...
最新文章
- 今日 Paper | 多人线性模型;身体捕捉;会话问答;自然语言解析;神经语义
- Spring Boot 入门
- 软件项目管理0703:净收确认
- JZOJ 5197. 【NOIP2017提高组模拟7.3】C
- iospython开发工具_使用Python开发iOS程序
- mybatis plus generator配置
- 分析 Web 资源的访问过程(Servlet 程序访问过程)
- 超级实用的内存泄漏归纳分析心得
- 【读书笔记】金字塔原理-目录
- VmWare虚拟机增加硬盘容量的方法
- i7 1165g7和i7 9750h 哪个好
- ubuntu简易教程(如何使用noi linux)
- C++——素数(质数)专题训练
- 删除带头结点的单链表的奇数结点
- Web作业表单的制作
- 如何批量重命名图片,文档,文件夹名字 Windows CMD 批量修改文件名字 内含修改路径的操作,想改哪里改哪里!
- wz的作战演习计划--分治思想
- NodeJS 安装及环境配置-Win10
- uniapp 中APP使用微信授权登录完整总结
- html动感相册怎么转成视频,如何导入要制作成视频的照片和视频短片【详细介绍】...