Created
January 25, 2012 13:51
-
-
Save dmethvin/1676346 to your computer and use it in GitHub Desktop.
Breakpoint on access to a property
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
function debugAccess(obj, prop, debugGet){ | |
var origValue = obj[prop]; | |
Object.defineProperty(obj, prop, { | |
get: function () { | |
if ( debugGet ) | |
debugger; | |
return origValue; | |
}, | |
set: function(val) { | |
debugger; | |
return origValue = val; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The snippet above makes property assignments lose their side effects (e.g.
document.body.scrollTop
controlling the scroll position on the page).You can use this code to call through to the original getter/setter functions.