Home  >  Article  >  Web Front-end  >  In-depth explanation of js overwriting original methods and providing rewriting methods

In-depth explanation of js overwriting original methods and providing rewriting methods

亚连
亚连Original
2018-05-17 10:17:433900browse

If you make an editor, which provides some cursor leave events, etc., it is best to use this method to operate, because When others use your editor, they may need to use the event methods provided by the editor to handle some things. Some of the events need to be rewritten according to special requirements. Therefore, when this happens, provide the event method that allows the rewriting of the events provided by the editor. Method is very necessary!

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<script> 
    function myblur () { 
        alert("1、离开"); 
    } 
    function bindEvent(func){ 
        myblur = func; 
    } 
    function myonclick() { 
        bindEvent(function(){ 
            alert("天啊!myblur方法被覆盖了!"); 
        }); 
    } 
</script> 
</head> 
<body> 
<input type="text" onblur="myblur()" value="光标选中然后光标离开会调用myblur()方法"/> 
<input type="button" onclick="myonclick()" value="覆盖myblur()" /> 
注:覆盖myblur()后,再次光标选中输入框然后再离开 
</body> 
</html>

Purpose: To improve the perfect calling method.

The above is the js I compiled for everyone to cover the original method and provide a rewriting method. I hope it will be helpful to everyone in the future.

Related articles:

javascript simulated overloading, detailed answers to rewriting the toString method

Detailed explanation of JS rewriting Writing prototype objects

Detailed explanation of overwriting and overloading techniques of js methods

The above is the detailed content of In-depth explanation of js overwriting original methods and providing rewriting methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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