zoukankan      html  css  js  c++  java
  • 前端常用的库和实用技术之JavaScript面向切面编程

    Aspect Oriented Programming(AOP)面向切面编程是一个比较热门的话题。
    AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程
    中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效果。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <script>
            function test(){
                // var start = 
                alert(2);
                return 'me test'
                // var end=;
                // console.log(end-start);
            }
            Function.prototype.before = function(fn){
                var _self = this;
              return function(){
                //   this指向了调用的函数
               if(fn.apply(this,arguments)==false){
                    return false;
               }
               return  _self.apply(_self,arguments)
                
              }
               
            }
            Function.prototype.after = function(fn){
                // after先执行本身this,再执行回调
                var _self = this;
               return function(){
               var result = _self.apply(_self,arguments);
               if(result == false){
                   return false;
               }
                fn.apply(this.arguments);
                return result;
               }
            }
            // test.before(function(){
            //     alert(1);
            // });
            // test.after(function(){
            //     alert(3);
            // })
            test.after(function(){
                alert(3);
                // return false;
            }).before(function(){
                alert(1);
                // return false;
            })();
            // 统计一下当前的所有的函数谁耗时最长
        </script>
    </body>
    </html>
    

    by没有看懂,压根不懂
    本文看自前端常用的库和实用技术之JavaScript面向切面编程

  • 相关阅读:
    经典的标量子查询
    Perl 正则二
    v$sql和v$sqlarea
    Flex中TabNavigator隐藏和显示选项卡
    如何优化buffer_cache
    perl 限制用户操作
    perl 正则
    latch 为什么消耗CPU
    Oracle 写脏数据的不同场景
    block放入哪个hash bucket算法
  • 原文地址:https://www.cnblogs.com/smart-girl/p/11549767.html
Copyright © 2011-2022 走看看