-
-
Save bensimian/7017443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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