问题:
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
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4281647