当前位置:网站首页>new的实现
new的实现
2022-04-23 06:26:00 【笔描相思】
1:首先会创建一个对象
2:创建构造函数上面的属性和方法给这个对象
3:将这个对象的__proto__的属性赋一个构造函数的protypeof
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
</title>
<script>
// alert(2423)
// console.log("423");
function Person(name,age)
{
this.name=name;
this.age=age;
}
function _New()
{
//创建一个对象
const obj={};
const [Person1,...arg]=[...arguments];
//给对象创建构造函数中的属性和方法
var res=Person1.apply(obj,arg);
//实例的显示原型指向构造函数的显示原型
obj.__proto__=Person1.prototype;
//如果构造函数自己有返回值,并且是对象的话我们就使用这个对象,否则就返回刚刚创建的对象
return res==='Object'?res:obj;
}
console.log(_New(Person,'小明',15));
</script>
</head>
<body>
</body>
</html>
版权声明
本文为[笔描相思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44788119/article/details/120902190
边栏推荐
- SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
- MySQL isolation level
- 快速傅里叶变换FFT简明教程
- 1. View databases and tables
- 2. Restricted query
- SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
- Mobile game performance optimization
- js之排他思想及案例
- AuthorizationServer(授权服务器的简单搭建)
- Solutions to common problems in visualization (VII) solutions to drawing scale setting
猜你喜欢
Discussion on arrow function of ES6
Nacos / sentinel gateway current limiting and grouping (code)
js之DOM学习获取元素
自定义时间格式(YYYY-MM-DD HH:mm:ss 星期X)
[Educational Codeforces Round 80] 解题报告
Design optimization of MySQL database
反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
Authorization server (simple construction of authorization server)
‘npm‘不是内部或外部命令,也不是可运行的程序 或批处理文件
js之排他思想及案例
随机推荐
[CodeForces - 208E] Blood Cousins(k代兄弟问题)
Solutions to common problems in visualization (VII) solutions to drawing scale setting
9. Common functions
12. Constraints
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
F-牛妹的苹果树(直径合并)
Authorization server (simple construction of authorization server)
ogldev-读书笔记
4.多表查询
Mysql 索引
Mvcc (multi version concurrency control)
js之作用域、作用域链、全局变量和局部变量
14.事务处理
The difference and application of VR, AR and MR, as well as some implementation principles of AR technology
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
10.更新操作
typescript字典的使用
Nacos / sentinel gateway current limiting and grouping (code)
【TED系列】如何与内心深处的批评家相处?
promise all的实现