Andrei Oniga Andrei Oniga - 1 year ago 76
Javascript Question

What is a JavaScript "Proxy Pattern"?

I've come across the notion of 'Proxy Pattern' today on, but could not make anything of it. Apparently it is of great use, but I do not understand the idea at all, it sounds alien to me. Could someone please explain it to me in simple terms, "as if I were a 3 year old"?


Imagine you have site with many ajax requests. There is a change in design. Now before each request you want to display some custom loading gif. You neeed to change all the code where there is an ajax request or you can use proxy pattern.

var proxied = jQuery.ajax; // Preserving original function
jQuery.ajax = function() { 
    jQuery("#loading").dialog({modal: true});
    return proxied.apply(this, arguments);