JavaScript的“新”关键字被视为有害吗? [关闭]

与世无争的帅哥 提交于 2020-08-06 04:16:06

问题:

In another question , a user pointed out that the new keyword was dangerous to use and proposed a solution to object creation that did not use new . 在另一个问题中 ,用户指出new关键字使用起来很危险,并提出了一种不使用new对象创建解决方案。 I didn't believe that was true, mostly because I've used Prototype, Scriptaculous and other excellent JavaScript libraries, and everyone of them used the new keyword. 我不相信这是真的,主要是因为我使用了Prototype,Scriptaculous和其他优秀的JavaScript库,并且每个人都使用了new关键字。

In spite of that, yesterday I was watching Douglas Crockford's talk at YUI theater and he said the exactly same thing, that he didn't use the new keyword anymore in his code ( Crockford on JavaScript - Act III: Function the Ultimate - 50:23 minutes ). 尽管如此,昨天我正在观看道格拉斯·克罗克福德在YUI剧院的演讲,他说同样的事情,他不再在他的代码中使用new关键字( Crockford on JavaScript - Act III:Function the Ultimate - 50: 23分钟 )。

Is it 'bad' to use the new keyword? 使用new关键字“不好”吗? What are the advantages and disadvantages of using it? 使用它有哪些优缺点?


解决方案:

参考一: https://stackoom.com/question/1bju/JavaScript的-新-关键字被视为有害吗-关闭
参考二: https://oldbug.net/q/1bju/Is-JavaScript-s-new-keyword-considered-harmful-closed
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!