Named vs. Anonymous Function: Identical?

Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}
What is the difference between these 2 function syntax types

In JavaScript, we can define a function, which will be called at a later time, using one of the methods below. That is, using a named function and assigning an anonymous function to a variable.

function myAdd(a, b) {
    console.log(a + b);
}
myAdd(3, 2);

var mySubtract = function (a, b) {
    console.log(a - b);
}
mySubtract(3, 2);

Are they basically always identical? By identical, I mean no special contexts that might make them different. For example, it turns out multiple left-hand assignment has some subtleties that might lead to a different result depending on the context.


函数声明被提升(并且可以在范围中的任何地方使用),函数表达式仅在赋值后才可用。

链接地址: http://www.djcxy.com/p/69986.html

上一篇: JavaScript分配自变量

下一篇: 命名与匿名功能:相同?