javascript - `Object.create(ctor.prototype)` 和 `new ctor()` 之间的区别
问题描述
在 VS Code 的源代码中,我发现了这样一段代码:
(打字稿)
/**
* Creates a new object of the provided class and will call the constructor with
* any additional argument supplied.
*/
export function create(ctor: Function, ...args: any[]): any {
let obj = Object.create(ctor.prototype);
ctor.apply(obj, args);
return obj;
}
我认为它与new ctor(...args)
.
不是吗?
解决方案
推荐阅读
- c++ - 如何修复以代码 2 退出的“CL.exe”
- python - VI_ERROR_TMO (-1073807339): 操作完成前超时
- java - 复杂聚合
- ios - 如何在 iOS Storekit 中使用多个捆绑包 ID
- c# - PHP 使用 c# DLL 参数类型问题
- yii2 - Yii2:Oracle (oci) 格式的子查询
- javascript - 如何使用 for 循环构建一系列承诺的响应?
- python - 带有自签名证书的 Authlib SSLError
- c# - 使用 EnsureCreatedAsync 后 MigrateAsync
- angular - RXJS 在管道内组合多个可观察对象