What is the nature of the data structure used to store the name of a function in JavaScript?
In other words, where is the string "Foo" (ie the name of the function Foo
) stored when this code is evaluated?
function Foo() {}
Also, do anonymous functions have a hidden name?
where is the string "Foo" (ie the name of the function Foo) stored
In the global scope.
You can avoid this by using a self invoking anonymous function :
(function() {
alert('Hello World');
})();
, or by associating a var to a function within a local scope :
function myBigFunction() {
var myfunction = function foo(){alert('Hello World');};
}
No hidden name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.