function Login(domElem, lib) { domElem.addEventListener('submit', function(e) { e.preventDefault(); lib.send({tag: "LogIn", name: domElem.name.value}) }); domElem.leave.addEventListener('click', function(e) { e.preventDefault(); lib.send({tag: "LogOut"}) }); return { on: on, off: off }; function on(name) { domElem.className = "on"; } function off() { domElem.className = ""; } }