What is the difference between these?
var myFunc = function() {
// ...
};
vs.
var myFunc = function myFunc() {
// ...
};
In the 2nd example, arguments.callee.caller.name works, but not in the first one. Is there anything wrong with the 2nd syntax?
The second one has a name while the first one doesn't. Functions are objects that have a property name. If the function is anonymous then it has no name.
var a = function(){}; // anonymous function expression
a.name; //= empty
var a = function foo(){}; // named function expression
a.name; //= foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With