It means that if the function was called without the new
operator, it will automagically return a new instance.
For example, if you didn't have this safeguard, and did this...
var t = Terminal();
...then the this
while executing Terminal()
would point to window
(or your global object, fancy non-browser guy/gal), definitely not what you want.
By determining that this
is in fact an instance of Terminal
, then we can proceed. Otherwise, the safeguard returns a new object.
Then we can simply use both forms...
var t = Terminal(); // Will be same as `new Terminal()`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…