Document http://html5ify.com/eventproxy/api.html first
Var EventProxy = require (". /eventproxy'); var proxy = new eventproxy (); var add = function (v1, v2, v3) {console. log (v1 + v2 + v3 + '') ;}; proxy. assign ("v1", "v2", "v3", add); clinet1.get ("key1", function (err, data) {// do something proxy. trigger ("v1", data) ;}); clinet2.get ("data", function (err, data) {// do something proxy. trigger ("v2", data) ;}); clinet3.get ("l10n", function (err, data) {// do something proxy. trigger ("v3", data );});
In JS programming, there is often such a need: To generate a page, the data is ajax, the template is also ajax to obtain, the general approach is to first send an ajax request to retrieve data, wait for the permanent request to complete and then send an ajax request to fetch the template, and then render it. In fact, the request data and the request template are both initiated at the same time and can be rendered when both are returned. This eventproxy is something to write for convenience.