-
-
Save ThomasG77/d4a6d55663d524237c14 to your computer and use it in GitHub Desktop.
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
define([ | |
'my/superModule', | |
'wrapper'; | |
], function (superModule, wrapper) { | |
// Let's wrap it, aspect style | |
wrapper(superModule, 'superModule'); | |
// Tada, all superModule methods will now log | |
}); |
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
define([ | |
'underscore' | |
], function (_) { | |
return function (toWrap, identifier) { | |
_(toWrap) | |
.chain() | |
.functions() | |
.each(function (method) { | |
var oldMethod = toWrap[method]; | |
toWrap[method] = function () { | |
var groupName = identifier + ': ' + method; | |
console.group(groupName); | |
console.log('%s args: %o', method, arguments); | |
var value = oldMethod.apply(this, arguments); | |
console.log('%s return value: %o', method, value); | |
console.groupEnd(groupName); | |
return value; | |
}; | |
}); | |
return toWrap; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment