zoukankan      html  css  js  c++  java
  • javascript面向切面

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>面向切面</title>
        <style type="text/css">
    
        </style>
    </head>
    
    <body>
        <input onclick="voice()" type="button" id="bn" value="动我就叫人来">
        <script type="text/javascript">
        function voice() {
            alert("救命啊!");
        }
        Aspects = function() {};
        Aspects.prototype = {
            before: function(target, method, advice) {
                var original = target[method];
                target[method] = function() {
                    (advice)();
                    original.apply(target, arguments);
                }
                return target
            },
            after: function(target, method, advice) {
                var original = target[method];
                target[method] = function() {
                    original.apply(target, arguments);
                    (advice)();
                }
                return target
            },
            around: function(target, method, advice) {
                var original = target[method];
                target[method] = function() {
                    (advice)();
                    original.apply(target, arguments);
                    (advice)();
                }
                return target
            }
        }
        window.onload = function() {
            var bn = document.getElementById("bn");
            var a = new Aspects;
            a.after(bn, "onclick", function() {
                alert("HELP!HELP!")
            });
        }
        </script>
    </body>
    
    </html>
  • 相关阅读:
    质因数分解
    P1939 【模板】矩阵加速(数列)
    UVALive
    Python操作MySQL:pymysql模块
    Mysql数据库基础
    Redis管道和发布订阅
    Redis常用操作
    Redis操作集合,有序集合
    Redis操作list
    Redis操作hash
  • 原文地址:https://www.cnblogs.com/lgxlsm/p/5755322.html
Copyright © 2011-2022 走看看