我有时会看到这种模式被使用
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;
}
}
谢谢