When debugging JavaScript programs, sometimes you need to print the stack information of the function call, which can be achieved by using console.trace(). The following code is an example:
The code copy is as follows:
function doTask(){
doSubTask(1000,10000);
}
function doSubTask(countX,countY){
for(var i=0;i<countX;i++){
for(var j=0;j<countY;j++){}
}
console.trace();
}
doTask();
Insert a line of console.trace() statement at the end of the execution of the doSubTask() function, which prints the function call stack information there in the debug console. For example, in the Firebug console it looks like this:
In the Firebug console, console.trace() will not only print the function call stack information, but also display the values of each parameter in the function call.
Browser support
console.trace(), like console.log(), supports better in browsers with debugging tools, and all major browsers support this function.