How does js override the old method implementation
- 2020-03-30 03:50:53
- OfStack
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script>
function myblur () {
alert("1 And leave ");
}
function bindEvent(func){
myblur = func;
}
function myonclick() {
bindEvent(function(){
alert(" Oh my god !myblur Method overwritten! ");
});
}
</script>
</head>
<body>
<input type="text" onblur="myblur()" value=" It is called when the cursor is selected and then left myblur() methods "/>
<input type="button" onclick="myonclick()" value=" cover myblur()" />
Note: the coverage myblur() After that, select the input box again and then leave
</body>
</html>
Purpose: to improve the perfect invocation method.
If you do a editor, there are offers some cursor left events, etc., it is best to use this method to operate, because when others using your editor, it may be used provided by the editor event method to deal with some things, some of these events need to rewrite according to special requirements, therefore, appear this kind of circumstance, allowed to rewrite the editor provides the event method is necessary!