1<!DOCTYPE html> 2<html lang="en"> 3 <meta charset="utf-8"> 4 <title>Eve Use Case</title> 5 <script src="eve.js"></script> 6 <script> 7 var log = function (text) { 8 log.log = log.log || []; 9 log.log.push(text); 10 }; 11 window.onload = function () { 12 document.getElementById("res").innerHTML = log.log.join("<br>"); 13 }; 14 </script> 15 <script> 16 var f1, f2, f3, f4; 17 18 // setting up listeners 19 eve.on("hit", f1 = function () { 20 log(" I’m hit!"); 21 }); 22 eve.on("hit/face", f2 = function () { 23 log(" Oh, my face!"); 24 }); 25 eve.on("hit/chest", f3 = function () { 26 log(" Oh, my chest!"); 27 }); 28 eve.on("hit/*/leg", f4 = function () { 29 log(" Ouch!"); 30 }); 31 eve.once("hit", function () { 32 log(" You scoundrel!"); 33 })(-1); 34 35 // fire events 36 log("In your face!"); 37 eve("hit/face"); 38 // I’m hit! 39 // Oh, my face! 40 log("Take that!"); 41 // You can use “.” or “/” as delimiter 42 eve("hit.chest.leg"); 43 // I’m hit! 44 // Oh, my chest! 45 // Ouch! 46 47 // Unbinding 48 log(""); 49 eve.unbind("hit", f3); 50 log("Take that!"); 51 eve("hit.chest.leg"); 52 // I’m hit! 53 // Ouch! 54 55 // Unbinding by wildcard 56 log(""); 57 eve.unbind("hit/*"); 58 log("In your face!"); 59 eve("hit.face"); 60 // I’m hit! 61 log("Take that!"); 62 eve("hit.chest.leg"); 63 // I’m hit! 64 </script> 65 <pre id="res"></pre> 66</html> 67