Core tip: The function name is GetFuncName, and the GetFuncName function is used directly in order to get the JavaScript function name
Gets the method that Javscript executes the function name, as follows:
The function name is GetFuncName, and the GetFuncName function is used directly in order to get the JavaScript function name
<script language= "JavaScript" >
function GetFuncName (_callee) {
var _text = _callee.tostring ();
var _scriptarr = document.scripts;
for (var i=0; i<_scriptarr.length; i++) {
var _start = _scriptarr[I].text.indexof (_text);
if (_start!=-1) {
if (/^function\s*\ (. *\). *\r\n/.test (_text)) {
var _temparr = _scriptarr[i].text.substr (0, _start). Split (' \ r \ n ');
Return _temparr[_temparr.length-1].replace (/(Var) (\s*)/g, '). Replace (/=/g, ');
} else {
Return _text.match (/^function\s* ([^\ (]+). *\r\n/) [1];
}
}
}
}
function A () {
Return GetFuncName (Arguments.callee);
}
var B = function () {
Return GetFuncName (Arguments.callee);
}
Window.alert (A ());
Window.alert (b ());
</script>
Get Javscript to execute a function name