Going back to javascript after years of polymer and react and this little gem has got me stumped, I'm trying to make a little library that can be included in my customer's web pages.
"use strict";
const MyLib = mylib();
function mylib() {
const res = {
init:(data) => {
const doSomthing = () => {
console.log('somthing', data)
}
const btn = document.getElementById('my-btn');
console.log('REMOVING EVENT LISTENER')
btn.removeEventListener('click', doSomthing, false);
console.log('ADDING EVENT LISTENER')
btn.addEventListener('click', doSomthing, false);
}
};
return res;
}
if then if I call MyLib.init({some: 'data'}) twice I expect just one event listener to be on my-btn but there is 2, I don't get it?