当前位置:网站首页>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
边栏推荐
- Common DOS commands
- Redis connection error err auth < password > called without any password configured for the default user
- 12. Constraints
- 4. Multi table query
- MySQL storage engine
- [hdu6833]A Very Easy Math Problem(莫比乌斯反演)
- SAP DEBUG调试FOR IN、REDUCE等复杂的语句
- 9.常用函数
- js之DOM学习获取元素
- [Ted series] how does a habit change my life
猜你喜欢
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
Discussion on arrow function of ES6
SAP PI/PO登录使用及基本功能简介
ABAP 实现发布RESTful服务供外部调用示例
keytool: command not found
MySQL index
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
Implementation of MySQL persistence
SAP PI/PO rfc2Soap 发布rfc接口为ws示例
ABAP 7.4 SQL Window Expression
随机推荐
Thorough inquiry -- understanding and analysis of cocos2d source code
4. Multi table query
2. Restricted query
Nacos/sentinel网关限流和分组 (代码)
10.更新操作
14. Transaction processing
10. Update operation
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
数组扁平化
Mvcc (multi version concurrency control)
关于素数的不到100个秘密
js中对象的三种创建方式
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
js之排他思想及案例
SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)
SAP PI/PO Soap2Proxy 消费外部ws示例
11. Table and library management
[Ted series] how to get along with inner critics?
MySQL isolation level
配置npm