On May 2, 2:09 pm, Maguila007 <leonemat...@gmail.comwrote:
On May 2, 2:16 pm, Geoffrey Summerhayes <sumr...@gmail.comwrote:
>
>
>
>
>
On May 2, 12:28 pm, Maguila007 <leonemat...@gmail.comwrote:
>
>
Is there any way to obtain the name of the function, inside the
function which was called.
>
>
>
alert( "The name of the function you invoke is " ......should
says 'something' );
>
>
Sort of..
>
function functionName(fn)
{
var name=/\W*function\s+([\w\$]+)\(/.exec(fn);
if(!name)return 'No name';
return name[1];
>
}
>
function foo(){alert(functionName(foo))}
>
Of course, it would be easier to write:
>
function foo(){alert('foo')}
>
and get the same effect.
>
Also
>
var bar=foo;
foo(); ->gives 'foo'
bar(); ->gives 'foo'
>
and
>
var foo=function(){alert(functionName(foo))};
var bar=foo;
foo(); -gives 'No name'
bar(); -gives 'No name'
>
----
Geoff
>
But I need to know "what is my name" inside the function, I do not
have a variable pointing to the function.
Of course you do. To work it requires the function to be written in
the form 'function *name* () {} so using *name* inside automatically
refers to the function unless you override it with a variable
definition.
If you use an obfuscation program on it, it should alter both to the
same to be correct.
I tested the callee.name and it´s work great for my porpouse in
Mozilla.
Is there anything like that for IE and Opera?-
arguments.callee initially contains the function body being executed
(ref ECMA 262 '97)
You'll have to extract the function name from there.
----
Geoff