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>

 

posted @ 2014-06-28 18:44  自由出土文物  阅读(1190)  评论(0编辑  收藏  举报