当前位置:网站首页>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
边栏推荐
- Emergency air space integrated communication system scheme of Guangxi Power Grid
- Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
- Intuitive understanding of torch nn. Unfold
- 可视化之路(九)Arrow类详解
- go语言切片操作
- pytorch:关于GradReverseLayer实现的一个坑
- golang实现正则匹配:密码包含至少一位数字,字母和特殊字符,且长度8-16
- LATEX使用
- (一)OpenPAI jupyter jupyterhub jupyterlab 方案比较
- PyTorch 13. Nested functions and closures (dog head)
猜你喜欢

jvm知识点汇总-持续更新

el-select 中v-model绑定值,数据回显只显示value,不显示label

学习笔记6-几种深度学习卷积神经网络的总结

Are realrange and einsum really elegant

USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference

华为云MVP邮件

电力行业巡检对讲通信系统

不需要破解markdown编辑工具Typora

学习资料

PyTorch 10. Learning rate
随机推荐
可视化常见绘图(三)面积图
VScode
技术小白的第一篇(表达自己)
Draw margin curve in arcface
PC端一次启动多个微信
快速下载vscode的方法
Object.create()原理,Object.create()规范,手写Object.create(),Object.create()用法
利用mysql-binlog恢复数据
Transformer的pytorch实现
小程序换行符\n失效问题解决-日常踩坑
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
Intuitive understanding of torch nn. Unfold
SDC intelligent communication patrol management system of Nanfang investment building
学习笔记6-几种深度学习卷积神经网络的总结
如何将进程绑定到指定的CPU上
go语言数组操作
商业版阿里MQ普通消息发送订阅Demo
golang实现一个带Web界面的五险一金计算器
按需引入vant组件
北峰通信助力湛江市消防支队构建PDT无线通信系统