Last active
August 29, 2015 14:07
-
-
Save brianblakely/dee73555e7602459759a to your computer and use it in GitHub Desktop.
Object.observe for JavaScript Debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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