Skip to content

Instantly share code, notes, and snippets.

@bensimian
Forked from ElliotChong/proxy.js
Created October 17, 2013 00:39
Show Gist options
  • Select an option

  • Save bensimian/7017443 to your computer and use it in GitHub Desktop.

Select an option

Save bensimian/7017443 to your computer and use it in GitHub Desktop.
/**
* JavaScript implementation of a Proxy class.
**/
​function Proxy(p_target)
{
var self = this;
self.target = p_target;
// Access target's properties
self.get = function (p_property)
{
return self.target[p_property];
}
self.set = function (p_property, p_value)
{
self.target[p_property] = p_value;
}
// Proxy target's functions
for (var key in self.target)
{
if (typeof self.target[key] === 'function')
{
self[key] = function ()
{
return self.target[key].apply(self.target, arguments);
}
}
}
}
Proxy.prototype = new Object();​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment