Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36186
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2019-03-27 01:03 -0700 |
| References | <10e6bc28-bec2-4796-81af-a4159fc0cb96@googlegroups.com> <06177936-cef7-4b93-8441-38c9c4b76781@googlegroups.com> <e8b78c13-42d4-4aaa-8898-1524106989fd@googlegroups.com> |
| Message-ID | <4186fe48-5403-42db-92fc-6f3e4e1aef74@googlegroups.com> (permalink) |
| Subject | Re: Event handler/listener syntax |
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
Den onsdag 27 mars 2019 kl. 08:57:30 UTC+1 skrev Jonas Thörnvall:
> Den onsdag 27 mars 2019 kl. 08:54:14 UTC+1 skrev Jonas Thörnvall:
> > Den onsdag 27 mars 2019 kl. 08:48:43 UTC+1 skrev Jonas Thörnvall:
> > > I find the eventhandler syntax weird "constructed" and hard to read, can you break out the actual code to to from eventhandler?
> > >
> > > document.getElementById("try").addEventListener("click", function(){
> > >
> > > });
> > >
> > >
> > > instead
> > >
> > > document.getElementById("try").addEventListener("click", dothis);
> > >
> > >
> > >
> > > function dothis(){
> > > document.getElementById("text").innerText = "GeeksforGeeks";
> > > }
> > >
> > > If not why was the former syntax chosen?
> >
> > Apparently i am not the only one finding the syntax a bit weird.
> >
> > https://stackoverflow.com/questions/16310423/addeventlistener-calls-the-function-without-me-even-asking-it-to
>
> Isn't this the natural way to do it????
> function message_me(m_text){
> alert(m_text)
> }
>
> second.addEventListener('click', message_me('shazam'))
Why the strange wrapping layer when you want todo something simple like?
function checkIfCharNotes(){
charNotes = document.getElementById("keyboardlistener").checked;
if (charNotes){ document.addEventListener("keydown", ListenKeybNote())}
else {document.addEventListener('keydown',nada());}
}
Because this is natural.
But the real syntax to do it is just weird? And i wonder how where they thinking.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Event handler/listener syntax Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-27 00:48 -0700
Re: Event handler/listener syntax Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-27 00:54 -0700
Re: Event handler/listener syntax Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-27 00:57 -0700
Re: Event handler/listener syntax Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-27 01:03 -0700
csiph-web