Tuesday, 15 March 2011

javascript - Get the name of the function from inside the function -


Is it possible to get the function name from inside the function?
Example:

  function myFunction () {// console.log Knowing the name of this function / what is the name / otherwise console.log (called 'myfunction') Was); // more clear (and better supported) than is console.log (myFunction.name); // console.log (arguments.callee.name); Works but not in strict mode and it has been removed)  

Reference:

Update: >>, it seems that this issue has been completely erased.
I have modified the example to make it clear.

Update 2:
It seems still still ... Here is an example of a debugging process:

  function one () {Console.log (arguments.callee.name + 'was called'); // one is called the // reset code /}} function called two () (console.log (arguments.callee.name + 'to'); // has been reset to // two) } Function three () {console.log (arguments.callee.name + 'was called'); // was reset code / / 3}} function four () {console.log (arguments.callee. Name + was called 'to'); // was called the // reset of code} function five () {console.log (arguments.callee.name + 'was called'); // said five Gets // // reset code) code  

arguments.callee.name is disliked and available in strict mode Dh is not.
I'm looking for a method that does not dislike and works in tough mode.

Try it ...

  console.log (myFunction. Name);  

Keep in mind that this is not supported by IE as


No comments:

Post a Comment