Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
ElectroArchiver3115134dIt's not the same,
addEventListener adds one listener,
while onmessage replaces all with
CoreFusionX1460134dStill, I don't know if that was his specific issue, but, in my limited frontend knowledge, shouldn't his callback be invoked no matter how he registered it?
@CoreFusionX Exactly! That’s what I am talking about!
@ElectroArchiver So if there are 5 different components using “window.onmessage”, there will actually be only one registered listener?
@Cyanide Exactly, you can try this in a new tab with devtools console opened:
window.onclick = () => console.log('test1')
window.onclick = () => console.log('test2')
You will only see 'test2' in the log when you click
Yes, but he specifically mentions that he fixed it by switching to .onmessage, which suggests he only has one listener whatsoever, which, again, *should*have been called with .addEventListener too.
@CoreFusionX Sure, I was answering his questions on how JS works, nothing more.
Yeah, all good. Yet I still want to know how it even happened in the first place. 😂
@CoreFusionX Well, he might have stopped event propagation in another listener..
@ElectroArchiver Nope. I didn’t.
@Cyanide Well it's hard to say without the code ^^
I had been banging my head on an issue for 2 days. The solution?
“window.onmessage = callback”
What. The. Actual. Fuck??!!
Aren’t they supposed to be the same thing?? It’s written on MDN’s article that the latter is an alternative way of doing the former.
What the fuck then? I am actually really pissed right now. Ragefully pissed.