Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active September 16, 2020 20:30
Show Gist options
  • Save simonewebdesign/6537339 to your computer and use it in GitHub Desktop.
Save simonewebdesign/6537339 to your computer and use it in GitHub Desktop.
Debugging a JS app with Aspect Oriented Programming
function applyDebug(obj) {
for (var f in obj) {
if (obj.hasOwnProperty(f) && typeof obj[f] === 'function') {
console.log(obj[f].toString());
origFunc = obj[f];
obj[f] = function () {
console.debug("called at " + new Date());
return origFunc.apply(this, arguments);
}
}
}
}
var Person = function() {
this.foo = "bar",
this.bar = function() {
return "baz";
}
};
var p = new Person;
applyDebug(p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment