Should I use new Type() or just Type() for calling a constructor

后端 未结 3 1671
天命终不由人
天命终不由人 2021-01-04 04:32

Both syntaxes are equivalent (at least I suppose they are).

let o1 = new Object()

or

let o2 = Object()

Wh

3条回答
  •  梦谈多话
    2021-01-04 05:25

    I feel like omitting "new" is a bit more functional, so that's my preference. I like that you can treat a constructor just like any other function returning an instance of a type.

提交回复
热议问题