Skip to main content

Timeline for LWC and addEventListener

Current License: CC BY-SA 4.0

12 events
when toggle format what by license comment
Feb 17, 2023 at 0:32 history edited sfdcfox CC BY-SA 4.0
deleted 8 characters in body
Feb 16, 2023 at 14:52 comment added Phil W Nice! Thanks for the link. Always learning...
Feb 16, 2023 at 14:38 comment added sfdcfox @PhilW It's the new private class fields. This makes it explicit that the property is not to be accessed outside the class.
Feb 16, 2023 at 14:24 comment added Phil W Explains the two approaches nicely now. Upvoted. Is there a specific reason you used the hash on the start of the identifier, btw?
Feb 16, 2023 at 14:23 comment added sfdcfox @PhilW Indeed. I've added more info to it. Thanks for calling that out.
Feb 16, 2023 at 14:23 history edited sfdcfox CC BY-SA 4.0
added 804 characters in body
Feb 16, 2023 at 14:22 comment added Phil W A-ha, yes, I should have read the whole piece of code and spotted the arrow function for this.receiveMessage. My fault for not being thorough, but it's a good idea to add a bit of detail in the answer too :D
Feb 16, 2023 at 14:18 comment added sfdcfox @PhilW I should have explained better, I suppose. Unlike normal function objects, Arrow functions (() => {}) keep their this to whatever scope they are defined in. receiveMessage(event) wouldn't work here, but receiveMessage = (event) => {...} does.
Feb 16, 2023 at 13:41 comment added Phil W Are you sure this is correct? AFAIK you lose the "this" binding for the component when adding the event listener this way (against window rather than this or this.template).
Aug 29, 2021 at 15:49 comment added TheLastEmperawr Thanks! That worked!
Aug 29, 2021 at 15:48 vote accept TheLastEmperawr
Aug 29, 2021 at 13:54 history answered sfdcfox CC BY-SA 4.0