[jQuery] Using Proxy Pattern to Override Methods

Tadashi Shigeoka ·  Tue, September 18, 2012

I researched how to override the alert method using the Proxy Pattern design pattern in jQuery, so here’s a memo.

(function() {
  var proxied = window.alert;
  window.alert = function() {
    // Add processing here
    return proxied.apply(this, arguments);
  };
})();

That’s all.

Reference Information

Types - jQuery JavaScript Library

override - JavaScript: Overriding alert() - Stack Overflow

必殺の .apply()フックを打つべし! 打つべし!(JavaScript おれおれ Advent Calendar 2011 – 17日目) | Ginpen.com

That’s all from the Gemba.