JavaScript decorators HOWTO?

decorator, javascript, jquery, prototype

Solution

What about your scenario requires a library? It seems that with native javascript, you could simply:

- Save a copy of the original function

- Create a modified version of the function which uses the original

- Store a reference to the modified version where the original was originally stored.

Problem

I need to decorate a 3rd party function that I can't modify so I will need to decorate it in any way. I found that in Prototype there is something to do it easily [1]. Is there any alternative to that in jQuery or in plain JavaScript? [1] http://api.prototypejs.org/language/Function/prototype/wrap/

Original source