• jquery09--Callbacks : 回调对象


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="jquery-2.0.3.js"></script>
    <script>
    //Callbacks管理回调。-------------------------------------------------------
    function aaa(){
        alert(1);
    }
    function bbb(){
        alert(2);
    }
    function ccc(){
        alert(3);
    }
    var cb = $.Callbacks();
    cb.add( aaa );
    cb.add( bbb );
    cb.add( ccc );
    cb.fire();
    
    //绑定事件,观察者模式
    document.addEventListener('click',function(){ alert(1); },false);
    document.addEventListener('click',function(){ alert(2); },false);
    document.addEventListener('click',function(){ alert(3); },false);
    ---------------------------------------------------------------------------
    
    function aaa(){
        alert(1);
    }
    (function(){
        function bbb(){//局部作用域
            alert(2);
        }
    })();
    aaa();
    bbb();
    ---------------------------------------------------------------------------
    var cb = $.Callbacks();
    function aaa(){
        alert(1);
    }
    cb.add(aaa);
    (function(){
        function bbb(){
            alert(2);
        }
        cb.add(bbb);
    })();
    cb.fire();//1  2
    
    ----------------------------------------------------------------------
    once
    memory
    unique
    stopOnFalse
    
    
    add
    remove
    has
    empty
    disable
    disabled
    lock
    locked
    fireWith
    fire
    fired
    -------------------------------------------------------------------------
    
    function aaa(){
        alert(1);
    }
    function bbb(){
        alert(2);
    }
    function ccc(){
        alert(3);
    }
    var cb = $.Callbacks();
    cb.add( aaa );
    cb.add( bbb );
    cb.add( ccc );
    cb.remove( bbb );
    cb.fire();
    </script>
    </head>
    
    <body>
    </body>
    </html>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="jquery-2.0.3.js"></script>
    <script>
    
    function aaa(){
        alert(1);
    }
    
    function bbb(){
        alert(2);
    }
    
    function ccc(){
        alert(3);
    }
    -------------------------------------------------------------------------
    var cb = $.Callbacks('once');
    
    cb.add( aaa );
    cb.add( bbb );
    
    cb.fire();
    cb.fire();//触发一次
    -------------------------------------------------------------------------
    var cb = $.Callbacks('memory');
    
    cb.add( aaa );
    
    cb.fire();
    
    cb.add( bbb );//弹出来,不写memory不谈,有memory又调用一次fire()
    --------------------------------------------------------------------------
    var cb = $.Callbacks('unique');
    
    cb.add( aaa );
    cb.add( aaa );
    
    cb.fire();//只执行一次
    ---------------------------------------------------------------------------
    function aaa1(){
        return false;
        alert(1);
    }    
    
    var cb = $.Callbacks('stopOnFalse');
    
    cb.add( aaa1 );
    cb.add( bbb );
    
    cb.fire();//只谈1不谈2
    ----------------------------------------------------------------------------
    var cb = $.Callbacks('once memory');//组合形式
    
    cb.add( aaa );
    
    cb.fire();//2也弹出来
    
    cb.add( bbb );
    
    cb.has (bbb );//true
    cb.fire();//不执行
    ------------------------------------------------------------
    options : { once : true , memory : true }
    
    optionsCache : {
        'once memory' : { once : true , memory : true }
    }
    ----------------------------------------------------------
    function aaa(n){
        alert('aaa' + n);
        return false;
    }
    function bbb(n){
        alert('bbb'+n);
    }
    var cb = $.Callbacks();
    cb.add(aaa,bbb);
    cb.fire('hello');
    cb.fire('hello');
    </script>
    </head>
    
    <body>
    </body>
    </html>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="jquery-2.0.3.js"></script>
    <script>
    ---------------------------------------------------------------------
    var bBtn = true;
    function aaa(){
        alert(1);
        if(bBtn){
            cb.fire();
            bBtn = false;
        }
    }
    function bbb(){
        alert(2);
    }
    var cb = $.Callbacks();
    cb.add( aaa );
    cb.add( bbb );
    cb.fire();
    ----------------------------------------------------------------------
    function aaa(){
        alert(1);
    }
    
    function bbb(){
        alert(2);
    }
    
    
    var cb = $.Callbacks('once memory');
    
    cb.add( aaa );
    
    cb.fire();
    
    cb.add( bbb );
    
    cb.fire();
    
    ---------------------------------------------------------------------------
    function aaa(){
        alert(1);
    }
    
    function bbb(){
        alert(2);
    }
    
    
    var cb = $.Callbacks('memory');
    
    cb.add( aaa );
    
    cb.fire();
    
    cb.lock();
    
    cb.add( bbb );
    
    cb.fire();
    
    </script>
    </head>
    
    <body>
    </body>
    </html>
  • 相关阅读:
    git pull 解决 refusing to merge unrelated histories 错误
    springboot 集成 jpa/hibernate
    hibernate(*.hbm.xml)中新添加的字段被标记为红色(找不到)的解决方法
    IntelliJ IDEA下自动生成Hibernate映射文件以及实体类
    HighGUI图形图像界面初步—— 图像的载入、显示与输出
    0_OpenCV3.4.0+Visual Studio2017 + win10环境配置
    5_Longest Palindromic Substring(Manacher) --LeetCode
    3_Longest Substring Without Repeating Characters -- LeetCode
    vs2017密钥
    2_基于深度学习的目标检测识别算法
  • 原文地址:https://www.cnblogs.com/yaowen/p/6914950.html
Copyright © 2020-2023  润新知