We always face debug issue in javascript and the time when we want to know which function actually create problem we set debug in all the function in sequence of calling. Since Javascript is not a very structured language it can sometimes be hard to get an overview of what happened and when so we have console.trace () to solve this problem.
Imagine you want to see the entire stack trace for the function call funcZ in the car instance.
var car;
var func1 = function(){
func2();
}
var func2 = function(){
func4();
}
var func3 = function(){
}
var func4 = function(){
car = new Car();
car.funcX();
}
var Car = function(){
this.brand = 'volvo';
this.color = 'red';
this.funcX = function(){
this.funcY();
}
this.funcY = function(){
this.funcZ();
}
this.funcZ = function(){
console.trace('trace car')
}
}
func1();
Output :
Now we can see that function func1 called func2 which called func4. Func4 created an instance of Car and then called the function car.funcX and so on.
0 Comment(s)