Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the stack trace for javascript function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 92
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: