js 实现 new Object

本文最后更新于 2024年4月26日 下午

这里只贴上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14

export function create() {
// 创建一个空对象
let obj = new Object()
// 获取对象的构造函数
let Con = [].shift.call(arguments)
// 链接到原型链
obg.__proto__ = Con.propotype
// 绑定this, 执行构造函数
let result = Con.apply.call(arguments)
// 确保new出来的是个对象
typeof result === 'object' ? result : obj
}


js 实现 new Object
https://dev.dgdream.online/2024/04/26/js 实现 nwe Object/
作者
执念
发布于
2024年4月26日
更新于
2024年4月26日
许可协议