Skip to content

Instantly share code, notes, and snippets.

@hojberg
Created December 8, 2009 15:24
Show Gist options
  • Save hojberg/251719 to your computer and use it in GitHub Desktop.
Save hojberg/251719 to your computer and use it in GitHub Desktop.
var app = {
before: function () { console.log("i am going to be runned before all other functions") },
func1: function () {
console.log("func1");
},
func2: function () {
console.log("func2");
}
};
for (var func in app) {
if (app.hasOwnProperty(func) && func != 'before') {
var oldfunc = app[func];
app[func] = function () {
app.before();
oldfunc();
}
}
}
app.func1();
// i am going to be runned before all other functions
// func1
app.func2();
// i am going to be runned before all other functions
// func2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment