Last active
October 15, 2023 16:56
-
-
Save antoineMoPa/8fee45a74f121575ab115de0a4579be3 to your computer and use it in GitHub Desktop.
Javascript debug on property set (debug on property changer)
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
const object_to_watch = obj; // Change to the object you are inspecting | |
const property_to_watch = 'example'; // Change to the property name in the object you are inspecting (here obj.example) | |
// Store the original value | |
object_to_watch.__storedValue = object_to_watch[property_to_watch]; | |
Object.defineProperty(object_to_watch, property_to_watch, { | |
get() { | |
return this.__storedValue; | |
}, | |
set(newValue) { | |
// Break when setting the value | |
// It can be useful to wrap this statement in a if () { } to check for specific values being set. | |
debugger; | |
this.__storedValue = newValue; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment