2

Basically, I want to add a breakpoint every time a given closure variable is changed. Is there any way to do this?

AlexZ
  • 9,637
  • 3
  • 24
  • 39

1 Answers1

4

I don't think there's currently a way to directly watch variables, but if you can put the closure variable in an object, then you can use Object.observe() to observe that object for changes. (Object.observe can only observe objects)
This requires you to have Experimental Javascript enabled - chrome://flags/#enable-javascript-harmony.

(function(){
  var holder = { 
    watchedVariable: "something"
  };

  Object.observe(holder, function (changes) {
    // returns an array of objects(changes)

    if ( changes[0].name === "watchedVariable" ) {
      debugger;
    }

  });

})()
  • Enabled experimental JS, relaunched chrome, and `Object.observe is not a function` – Kirkland Mar 06 '17 at 21:49
  • @Kirkland Object.observe is deprecated. see: http://stackoverflow.com/questions/36258502/why-has-object-observe-been-deprecated for reason and alternatives – Daniel Z. May 10 '17 at 10:59