-
Hi there, I'm questionning on the value of "this" in this simple example:
index.html is: Both buttons shows in the console : an instance of FooButton, and HTMLButtonElement item. Running example here: Can you tell me how to use "this" correctly in the "firstUpdated" method? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
What's the goal you're trying to achieve? How to use it correctly depends on what you're trying to do. There's a bit of "magic" involved when passing a function to the You can bind the context of |
Beta Was this translation helpful? Give feedback.
What's the goal you're trying to achieve? How to use it correctly depends on what you're trying to do.
There's a bit of "magic" involved when passing a function to the
@event
binding because the context ofthis
is bound to the element it's on unless specified otherwise as ahost
option https://lit.dev/docs/libraries/standalone-templates/#render-optionsYou can bind the context of
this
in the event handler by using arrow functions instead too.