我有时看到这种模式使用在javascript中的函数声明中命名函数有什么好处?
function foo() {
this.bar = function bar() {
// code
}
}
的优点是什么/之所以命名的功能,而不是它作为一个匿名函数?
为了进一步说明/澄清:
function foo() {
this.bar = function bar() {
bar.someVar = 1;
}
}
Vs的
function foo() {
this.bar = function() {
this.someVar = 1;
}
}
感谢
可能的重复 http://stackoverflow.com/questions/1013385/what-is-the-difference-between-a-function-expression-vs-declaration-in-javascrip – MasNotsram 2013-04-24 10:57:00