Last active
September 16, 2020 20:30
-
-
Save simonewebdesign/6537339 to your computer and use it in GitHub Desktop.
Debugging a JS app with Aspect Oriented Programming
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 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