Created
August 12, 2019 11:46
-
-
Save codesorter2015/ea2a41bd03e6d090c817dafad5f1f328 to your computer and use it in GitHub Desktop.
Create a proxy window object using javascript
This file contains 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
handler = { | |
get: function(target, property, receiver) { | |
let targetObj = target[property]; | |
if(typeof targetObj == "function") { | |
return (...args) => target[property].apply(target,args) | |
} else { | |
return targetObj; | |
} | |
} | |
} | |
windowProxyObject = new Proxy(window, handler); | |
Example: | |
windowProxyObject.document.getElementsByTagName('HTML'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment