Created
January 17, 2012 18:54
-
-
Save jbarnette/1628124 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
decorate: (n, fn) -> | |
target = this[n] | |
unless _.isFunction target | |
throw new Error "Can't decorate #{n}, it's not a Function." | |
unless target.fns? | |
wrap = -> | |
args = Array.prototype.slice.call arguments | |
finish = _.after wrap.fns.length, => wrap.old.apply this, args | |
_.each wrap.fns, (fn) => fn.call this, finish | |
_.extend wrap, fns: [], old: target | |
this[n] = target = wrap | |
target.fns.push fn | |
this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment