js的delegate回调例子

暂时没发现有具体的实际用处,先记录下

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>

</body>
</html>

<script>

    var CCaller =
    {
        createNew: function()
        {
            var instance = {};

            instance.delegate = null;
            instance.call = function(x)
            {
                if ( null != instance.delegate)
                {
                    instance.delegate.interfaceFuncImpl(x);
                }
            };

            return instance;
        }
    };

    var CInterfaceFuncImpl = {

        createNew: function()
        {
            var instance = {};

            instance.interfaceFuncImpl = function(arg)
            {
                alert(arg);
            };

            return instance;
        }
    };

    $(document).ready(function() {

        caller = CCaller.createNew();
        testImpl = CInterfaceFuncImpl.createNew();
        caller.delegate = testImpl;
        caller.call("asdasdasd");
    });

</script>

 

js的delegate回调例子,布布扣,bubuko.com

js的delegate回调例子

上一篇:376.摆动序列


下一篇:jmeter-配置分布式