Created
February 19, 2017 23:08
-
-
Save melbourne2991/7e58618694e68fdef8e107f0f1d59622 to your computer and use it in GitHub Desktop.
Fun with proxies :)
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
const HeaderAPI = {}; | |
HeaderAPI.updateAuthenticated = function() { | |
console.log('UPDATING!'); | |
} | |
class Header { | |
constructor() { | |
} | |
} | |
Header.prototype = new Proxy(Header.prototype, { | |
get(target, name) { | |
const proxiedMethods = ['updateAuthenticated']; | |
if(proxiedMethods.some((method) => method === name)) { | |
if(!window.HeaderAPI) { | |
return () => { console.log('This method is not defined!') } | |
} | |
return window.HeaderAPI[name]; | |
} | |
return target[name]; | |
} | |
}) | |
const proxyHeader = new Header(); | |
proxyHeader.updateAuthenticated(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment