The code information comes from http://ejohn.org/apps/learn/.
It can be referenced inside it by its name.
function Yell (n) { return n > 0? Yell (n-1) + "a": "Hiy";} console.log (Yell (4) = = = "Hiyaaaa", "In the inside of the function accesses itself through its name");
How do you call yourself inside a named function when it is not declared?
var ninja = { function(n) { return n > 0? arguments.callee (n-1 + "A": "Hiy"; }}; Console.log (Ninja.yell (4) = = "Hiyaaaa", "Arguments.callee refers to the function itself");
The name scope of the function is invalidated.
var function Myninja () { = = = Myninja, "the reference and name of this function is thesame function"typeof Myninja = = = "Undefined", " But not accessible outside the function " ); Console.log (ninja); // function Myninja ()
Note that when we use a named function declaration to assign to a variable, the name of the function can be referenced internally, but not externally. And the assigned variable can be referenced.
You can also call an anonymous function when it is a property of an object.
var ninja = { function(n) { return n > 0? ninja.yell (n-1) + "a": "Hiy"; }; Console.log (Ninja.yell (4) = = = "Hiyaaaa"); // true
Through the properties of this object, we can call it.
What happens when the original object is removed?
var ninja = {yell: function (n) { return n > 0? Ninja.yell (n-1) + "a": "Hiy" ; } }; Console.log (Ninja.yell ( 4) = = "Hiyaaaa"); // true var Samurai = {Yell:ninja.yell}; var ninja = null try {Samurai.yell ( 4); catch (E) {Console.log ( "cannot be accessed. "
The same thing, but what happens when we give the anonymous function a name?
var ninja = { function yell (n) { return n > 0? Yell (n-1) + "a": " Hiy "; }}; Console.log (Ninja.yell (4) = = "Hiyaaaa") ; var samurai =var ninja = null; Console.log (Samurai.yell (4) = = "Hiyaaaa", " Note that it can still call this function ");
JavaScript Advanced Knowledge Analysis--function access