zoukankan      html  css  js  c++  java
  • JavaScript的Hook

    <!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>

  • 相关阅读:
    第二次结对编程作业
    团队项目-需求分析报告
    团队项目-选题报告
    第一次结对编程作业
    第一次个人编程作业
    第一次博客作业
    第04组 团队Git现场编程实战
    第二次结对编程作业
    团队项目-需求分析报告
    团队项目-选题报告
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/2486243.html
Copyright © 2011-2022 走看看