当前位置:网站首页>Object. Create() principle, object Create() specification, handwritten object create(),Object. Create() usage
Object. Create() principle, object Create() specification, handwritten object create(),Object. Create() usage
2022-04-23 07:35:00 【XIX (procrastination)】
List of articles
1:Object.create() usage
Use an existing object to create a new object containing it , Assign the object to the prototype of the new object .
let obj = {
name:'anny'
}
let newObj = Object.create(obj);
console.log(newObj.name). // Output :anny
Attention list :
- The first parameter can only be Object Type or null, Otherwise, an error will be reported
- The second parameter is optional , Be similar to Object.defineProperties Second parameter of .
let obj = {
name:'anny'
}
let newObj = Object.create(obj,{
name:{
value:"tony",
writable:true // Is it possible to write
}
});
console.log(newObj.name) // Output tony
2:Object.create() Principle specification
2.1: standard
- Judge whether it is Object perhaps null
- Create a new object
- Point the prototype of the new object to the incoming object
- Judge the second parameter Properties It's true
- Return the newly created object
2.2: Realization
function myCreate(obj,Properties){
// Judge whether it is Object perhaps null
if(!(obj instanceof Object)&&obj!==null){
throw TypeError
}
// Create a new object ( Equivalent to new Object())
let newObj = {
}
// Point the prototype of the new object to the incoming object
newObj.__proto__ = obj;
// If the second parameter Properties It's true
if(Properties&&Properties!==undefined){
Object.defineProperties(newObj,Properties)
}
// Return the newly created object
return newObj;
}
Please do not reprint without my consent
版权声明
本文为[XIX (procrastination)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230618084953.html
边栏推荐
- golang实现一个带Web界面的五险一金计算器
- Solution of wireless intercom system in Commercial Plaza
- Wireless communication system for large-scale sports events
- 可视化常见绘图(三)面积图
- 关于'enum'枚举类型以及结构体的问题。
- colab
- 可视化常见绘图(四)柱状图
- pytorch:关于GradReverseLayer实现的一个坑
- Meishe helps Baidu "Duka editing" to make knowledge creation easier
- 学习笔记6-几种深度学习卷积神经网络的总结
猜你喜欢
记录一个查询兼容性的网站,String.replaceAll()兼容性报错
van-uploader上传图片实现过程、使用原生input实现上传图片
广西电网|应急空天一体化通信系统方案
“泉”力以赴·同“州”共济|北峰人一直在行动
el-date-picker中自定义快捷选项picker-options,动态设置禁用日期
Meishe helps Baidu "Duka editing" to make knowledge creation easier
Typora语法详解(一)
浅谈BFC(块格式化上下文)
PyTorch 10. Learning rate
el-select 中v-model绑定值,数据回显只显示value,不显示label
随机推荐
按需引入vant组件
可视化之路(九)Arrow类详解
Pycharm
Flexible blind patch of ad hoc network | Beifeng oil and gas field survey solution
Jupyter Notebook 安装
快速下载vscode的方法
可视化常见绘图(三)面积图
华为云MVP邮件
免费开源农业物联网云平台(Version:3.0.1)
启动mqbroker.cmd失败解决方法
PyTorch 18. torch. backends. cudnn
colab
无盲区、长续航|公专融合对讲机如何提升酒店服务效率?
字节数仓实习生面试sql题
Tensorflow安装后ImportError: DLL load failed: 找不到指定的模块,且国内安装缓慢
学习笔记7-深度神经网络优化
Us photo cloud editing helps BiliBili upgrade its experience
Source Insight 4.0常见问题
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
null和undefined的区别