我应该使用 new Type() 还是只使用 Type() 来调用构造函数 [英] Should I use new Type() or just Type() for calling a constructor

查看:20
本文介绍了我应该使用 new Type() 还是只使用 Type() 来调用构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两种语法是等价的(至少我认为它们是).

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

let o1 = new Object()

let o2 = Object()

您更经常使用哪种方式?可读性问题呢?

Which way do you use more often? What about readability issues?

推荐答案

它们是一样的.

我更喜欢使用new",除了我在其他语言中习惯的使用之外,没有什么好的理由,并且它可以更容易地为构造函数调用 findstr/grep(缺乏智能工具来查找所有引用"一个解决方案).

I prefer using 'new', with little good reason other than it is what I am accustomed to in other languages, and it makes it easier to findstr/grep for constructor calls (lacking smart tools to 'find all references' in a solution).

这篇关于我应该使用 new Type() 还是只使用 Type() 来调用构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆