Skip to content

Instantly share code, notes, and snippets.



Last active Oct 8, 2017
What would you like to do?
JavaScript function for annotating other JavaScript
function annotate(fnToAnnotate) {
// already annotation aware, use the original annotation chain
if ( {
return fnToAnnotate;
var aAnnotationChain = [fnToAnnotate];
function applyChainFunctions(fn) { = function(fnAnnotation, arg1, /*...*/ argN) {
var fnToAnnotate = aAnnotationChain[aAnnotationChain.length - 1],
fnExecutedAnnotation = function () {
Replace the annotation function in the args list,
with the function to annotate. This is a nice little hack
to allow us to call the annotation function using apply, passing
the function to annotate as the first argument, followed by
all the other arguments that were originally passed to ``by``.
arguments[0] = fnToAnnotate;
return fnAnnotation.apply(this, arguments);
}.apply(this, arguments);
return applyChainFunctions(fnExecutedAnnotation);
return fn;
return applyChainFunctions(fnToAnnotate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.