Below I will share with you an article about how a js native method is overwritten and the native method is reassigned. It has a good reference value and I hope it will be helpful to everyone.
Implementation Principle
# After the native method of js is overwritten, if you have not made the native method point to a new variable name again , then it’s gg. Therefore, the key is how to obtain the native method again. The principle of implementation is to create a new window object, and then obtain the native methods from the new window object to reassign values.
Use iframe implementation
First create an iframe object, use the document.createElement method to create
var iframe = document.createElement("iframe"); document.body.appendChild(iframe)
Then , get the window object in the iframe
var iframeWin = iframe.contentWindow;
Finally assign a value, you can
window.console = iframeWin.console;
Use the window.open method to achieve
window.open method call will open a new window and return a new window object, so we can get the window object like this
var win = window.open(); //获取对象 win.close(); //将打开的窗口关闭 window.console = win.console;
The above is what I compiled Everyone, I hope it will be helpful to everyone in the future.
Related articles:
How to implement bind in Javascript
How to implement encapsulation based on the mssql module in nodejs
How to implement the directive function in vue
How to prevent repeated rendering using React
How to implement grid using vue -layout function
Detailed introduction to adding drag and drop function to Modal in Bootstrap
How to achieve preview effect in JS
How to use ES6 syntax in Node (detailed tutorial)
In How to configure Sass in vue scaffolding
The above is the detailed content of How to implement reassignment using js. For more information, please follow other related articles on the PHP Chinese website!