If there is a constructor like
function a() {}
then
(new a) instanceof a === true
But on the other hand,
function a() { return {} }
results in
(new a) instanceof a === false
So what I was thinking is that
function a() { return 123 }
would result in the same thing. However, when returning a Number,
(new a) instanceof a === true
How is this possible? Why can't I make a constructor return something else than an Object?
(I do know making a constructor returning a Number is rather useless but I would like to understand the 'why' of this behaviour)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…