English 中文(简体)
如果卡罗克福德告诉我们不要使用新的关键词来继承遗产,那么为什么不使用这些新关键词?
原标题:Why does Crockford say not to use the new keyword if he advises us to use it for prototypal inheritance?
  • 时间:2011-11-20 16:24:05
  •  标签:
  • javascript

我看到了一个录像,Crockford告诉我们不要使用new关键词。 他说使用目标。 相反,如果我不错的话。 他为什么告诉我们不要使用<代码>新。 如果他在本条中利用这一遗产实现传承,他写道:http://javascript.crockford.com/prototypal.html

我期望他使用目标。 而不是<代码>new,如:

function object(o) {
    return Object.create((function() {}).prototype = o);
}

So why is it that he still uses new?

最佳回答

Crockford 讨论new。 摘录:

If you call a constructor function without the new prefix, instead of creating and initializing a new object, you will be damaging the global object. There is no compile time warning and no runtime warning. This is one of the language’s bad parts.

在实践中,我完全避免使用<条码>新

问题回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签