Skip to content

How to use event listeners with conditionals #2280

Answered by GHNewbiee
GHNewbiee asked this question in Q&A
Discussion options

You must be logged in to vote

As regards, accessing this.arg in the event listener methods, IMHO, it might not be very practical when:

  • method has enough arguments/parameters (eg x, y, z, k, m, n, p) which they are changed into relatively long property names (eg this._xScale, this._yScale, this._zScale, this._xDeflection, this._yDeflection, this._zDeflection, this._force) and appear many times with result in making code "ugly'.
  • method comes from another source/library and modification is not suggested due to source frequent updates
  • the same method is used more than once; for example, ten buttons as follows:
  render() {
    return html`
      <button @click=${this._commonMethod.bind(this, 'fwd')}>Fwd</button>
      <b…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@justinfagnani
Comment options

@justinfagnani
Comment options

Comment options

You must be logged in to vote
2 replies
@justinfagnani
Comment options

@GHNewbiee
Comment options

Answer selected by GHNewbiee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants