Skip to content

Instantly share code, notes, and snippets.

@brianblakely
Last active August 29, 2015 14:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianblakely/dee73555e7602459759a to your computer and use it in GitHub Desktop.
Save brianblakely/dee73555e7602459759a to your computer and use it in GitHub Desktop.
Object.observe for JavaScript Debugging
// By observing changes to an object with Object.observe,
// and turning on Async Call Stacks in Chrome Dev Tools,
// you can find the source of those changes.
var myObject = {
foo: 'bar'
};
Object.observe(myObject, function(changes) {
// This asynchronous callback runs when myObject is changed
changes.forEach(function(change) {
// Log out the change data for good insight
console.log(change);
// The debugger statement fires a Dev Tools breakpoint, creating a call trace
// MAKE SURE 'Async' is checked in Chrome Dev Tool's Call Stack drawer!
debugger;
});
});
function strangeChanges() {
myObject.foo = 'something unexpected';
}
strangeChanges();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment