<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <script src="http://code.jquery.com/jquery-latest.js"></script> <body> <script type="text/javascript"> (function($) { var o = $({}); $.subscribe = function() { o.on.apply(o, arguments); }; $.unsubscribe = function() { o.off.apply(o, arguments); }; $.publish = function() { o.trigger.apply(o, $.makeArray(arguments)); }; })(jQuery); //订阅 $.subscribe("test", function(e, a1, a2, a3, a4) { console.log(e.type + "," + a1 + "," + a2 + "," + a3 + "," + a4); }); //发布 $.publish("test", ["a", "b", "c", "d"]); </script> </script> </html>
时间: 2024-10-29 21:01:15