Skip to content

Instantly share code, notes, and snippets.

View FarisHijazi's full-sized avatar
:shipit:
ඞඞඞ

Faris Hijazi FarisHijazi

:shipit:
ඞඞඞ
View GitHub Profile
@FarisHijazi
FarisHijazi / snoopProperty.js
Created May 12, 2019 19:07
JavaScript snoop properties of objects. Bind callbacks to getters and setters for all properties of an object. Useful for observing how a page element has its properties accessed
/**
* Snoops on an object, monitors all attempts to access and set properties
* @param {Object} obj - the object to monitor
* @param {string[]=} props - list of properties to watch, watches all properties by default
* @param {Function=} onset - callback when the property is set (newValue is passed)
* @param {Function=} onget - callback when the property is accessed
* @param verbose
*/
function snoopProperty(obj, props = [], onset = (val) => null, onget = () => null, verbose = true) {