Call constructor on TypeScript class without new

后端 未结 6 958
醉话见心
醉话见心 2020-12-13 13:50

In JavaScript, I can define a constructor function which can be called with or without new:

function MyCl         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 14:03

    The keyword new is required for ES6 classes:

    However, you can only invoke a class via new, not via a function call (Sect. 9.2.2 in the spec) [source]

提交回复
热议问题