首页 > 解决方案 > `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).

不是吗?

标签: javascriptprototypeobject-create

解决方案


推荐阅读