Home >
Article > Web Front-end > How to solve the problem of this pointing to the bound element when using the attachEvent function_javascript skills
How to solve the problem of this pointing to the bound element when using the attachEvent function_javascript skills
WBOYOriginal
2016-05-16 19:10:461218browse
Using attachEvent to bind the same event multiple times is an important way to resolve conflicting event function definitions. But in IE, the this pointer in the function does not point to the bound element, but the function object. In the application, this is a very uncomfortable thing. If you try to use local variables to transfer elements, it will cause closure errors. Memory leak. So, how should we solve this problem?
I added the prototype method "bindNode" to Function. In this method, global storage conversion is performed based on the passed elements, and then the encapsulated function is returned, and the call method is used to perform owner conversion.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn