The example in this article describes the method that JavaScript implements to display function call stacks. Share to everyone for your reference, specific as follows:
The function call relationship between many large JavaScript applications is very complex, and it is important to understand the order in which the functions are invoked before they are triggered, often in the process of development or debugging, to track which functions are invoked.
Firebug provides console.trace () to display the function stack, and the following line of code where you need to debug can show the context of the function call. IE6 is not so convenient, it does not provide a tool to display the stack of functions, when the inevitable need to debug the code under IE6, Use the following code to display the function stack (it is recommended that the following JavaScript code be saved as Console.trace.js and referenced to the page through the external introduction of JS):
The JavaScript code is as follows:
/** * Get function name * * @param {function} func function Reference * @return {String} function name */functions Getfuncti Onname (func) {if (typeof func = = ' function ' | | typeof func = = ' object ') {var name = (' + func '). Match (/function\
s* ([\w\$]*) \s*\ (/);
Return name && name[1]; } if (! Console ' in Window ') {window.console = {};} if (!console.trace) {/** * display function Stack <br/> * For and firebug unification, TRAC The E method is added to the console object * @param {function} func functions reference * * @example function A () {B ();} function B () {C ();} func
tion C () {D ();} function D () {console.trace ();} a ();
*/console.trace = function () {var stack = [], caller = Arguments.callee.caller;
while (caller) {Stack.unshift (Getfunctionname (caller));
Caller = caller && Caller.caller;
Alert (' Functions on stack: ' + ' \ n ' + stack.join (' \ n '));
}
};
More readers interested in JavaScript-related content can view the site topics: "JavaScript switching effects and tips summary", "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and tips summary", " JavaScript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical calculation usage Summary
I hope this article will help you with JavaScript programming.