除了 class/function 之外,是否可以调用 new

Can new be called on anything other than a class/function

是否可以直接修改对象,以便可以使用 new 关键字创建它们,还是仅适用于 functions/classes?例如:

const bird = {
    swim() {return 'Swim';},
    fly() {return 'Fly';}
};
let b1 = Object.create(bird);

bird.constructor = function(){console.log('via constructor')};
let b2 = new bird();

这个没有实际用途,我只是在学习东西,看看 new 是如何工作的等等。

没有

使用 new 导致 EvaluateNew 被调用,

  1. If IsConstructor(constructor) is false, throw a TypeError exception.

哪个does

  1. If argument has a [[Construct]] internal method, return true.

内部 属性 是 only permitted on functions:

A constructor is an object that supports the [[Construct]] internal method. Every object that supports [[Construct]] must support [[Call]]; that is, every constructor must be a function object.