<!DOCTYPE html>
<html>
<head>
<title>hook</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
</head>
<body>
<input type='button' value='fuck' onclick='fuck()' />
<input type='button' value='hook' onclick='hook()' id='hookBtn' />
<script type='text/javascript'> 1:
2:
3: function fuck() {
4: alert('hook');
5: }
6:
7: var isHook = false;
8: var isReset = false;
9:
10: function getEl(id) {
11: return typeof id === 'string' ? document.getElementById(id) : null;
12: }
13:
14: function hook() {
15:
16: if (isHook) {
17: isReset = true;
18: getEl('hookBtn').value = 'hook';
19: } else {
20: fuck = function(fn) {
21: return function() {
22: if (isReset) {
23: isReset = false;
24: fuck = fn;
25: fn.apply(fn, arguments);
26: return ;
27: }
28:
29: alert('hook it~');
30: fn.apply(fn, arguments);
31:
32: return fn;
33: }
34: }(fuck);
35:
36: getEl('hookBtn').value = 'unHook';
37: }
38:
39: isHook = !isHook;
40: }
41:
</script>
</body>
</html>