Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript decorators HOWTO?

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/

like image 705
Esteban Feldman Avatar asked Dec 04 '09 18:12

Esteban Feldman


1 Answers

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.
like image 179
Frank Schwieterman Avatar answered Oct 25 '22 01:10

Frank Schwieterman