So basically I'm making my own Javascript framework/library. It has gone pretty good but I'm stuck on making my custom way of adding event listener.
Here's my code:
function $Listen(to,type,action){
to.addEventListener(type{action});
}
My expected result was such that you could now do something like this:
var tag=document.getElementById("tag")
$Listen(to=tag, type="click",action=function(){
alert("Hello")
});
Basically meaning when you click "tag" it alerts hello world, but the problem is, this script doesn't work. Is there anyway to make this code work? Also is there any way to make it easier to use my eventListener. for example:
tag.$Listen("click",function(){
//code goes here
})
If you can that will be great, but just so you don't confuse me too much, please first focus on fixing my error, and if you have time, then you can find a way to make it easier. Also, I enjoy the more lower lines code, or simpler owners, just keep that in mind. THANKS!