English 中文(简体)
比较预先申报和自发的匿名功能
原标题:Comparing Pre-declared and Self-invoked Anonymous Functions

这将是一次迅速的讨论,但我只想就今天上午的总结提出一些反馈意见。 了解这一点......

var addTwoNumbers = function(intOne, intTwo) {
    if ((typeof intOne ==  number ) && (typeof intTwo ==  number )) {
        document.write(intOne + intTwo);
    } else {
        document.write( Unable to perform operation. );
    }
};

addTwoNumbers(3, 4);

......行为与......基本相同......

(function(intOne, intTwo) {
    if ((typeof intOne ==  number ) && (typeof intTwo ==  number )) {
        document.write(intOne + intTwo);
    } else {
        document.write( Unable to perform operation. );
    }
})(3, 4);

......可以说,自发功能中的第一组母轮是“绕行”的,还是以提及的方式围绕职能执行开展工作? 实际上,() 是该方法的名称,实际上不是该方法的名称? 而且,由于该职能是在直接执行时宣布的,该职能是否比使用可变名称参照法的更快? 正义胜诉。

最佳回答

OK在座的理由是,“自发功能”(实际上是“自发”的;有明确的援引,有<>外在<>。 该功能是(根据公约)作为母体大小次低压书写的。

Java本有两个涉及关键词的构造:<条码>。

  1. 职能声明界定了功能标的,将其与当地范围(以及地方范围的职能)的名称挂钩,但现在却忽视:

    function foo() { /* code */ }
    
  2. The function instantiation sub-expression, which creates a function object in the context of an expression:

    var f = function() { /* code */ };
    

问题在于你何时想要第二点,,在发言开始时,你想要它。 当发言starts和关键词>>时,主讲人假定,你再做1,而不是2。 因此,通过围绕“instantiation<>>>>功能引入括号——并铭记一种次抑制的括号总是允许的,而且不会以任何方式影响其价值——使的使用成为可能。 关键词可解释为<>2。

还有一些强迫教区也把声明视为表达方式:

  • !function() { /* code */ }();
  • 0, function() { /* code */ }();
  • +function() { /* code */ }();

只是一些例子。

关于业绩,它不在此问。 我要指出的一件事是,这种对功能物体具有约束力的标识方式:

var name = function() { /* code */ };

确实比:

function name() { /* code */ }

在某些方面,这种情况更糟。 具体来说,使用职能声明,在用<条码>/条码”界定职能时,用记号表示。

问题回答

暂无回答




相关问题
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.