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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。