Hamabama
Hamabama

Reputation: 253

How to track the line where a variable has changed it's value?

I'm debugging Javascript app using Chrome dev tools and wondering if there any way to catch the exact line where a variable has changed its value? Object.observe seems not able to show the line number.

Upvotes: 1

Views: 220

Answers (1)

Lewis
Lewis

Reputation: 14906

var b;
Object.defineProperty(window,'a',{
	set : function(value){
		b = value;
		alert(new Error().stack.split('\n')[2]);
	},
	get : function(){
		return b;
	},
});
a = 1;

Upvotes: 1

Related Questions