Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of script.aculo.us, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Noko Time Tracking and Every Time Zone and write books like Retinafy.me.
   Want me to speak at your conference? Contact me!

JavaScript decorator pattern

August 25th, 2006

Decorator pattern in JavaScript? Sure can do. Read the article on how to augment arbitrary JavaScript objects with custom before and after events.

Basically, it boils down to this:


actsAsDecorator(Ajax.InPlaceEditor.prototype);
Ajax.InPlaceEditor.prototype.after(
  'enterEditMode', function() {
    // do something
  }
);

Nicely done, and very useful to add your own tweaks to existing JavaScript controls and components.