Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
Calling the this.method() inside function of another method

is there a way calling the createElement() method inside checkbox.off().on('click', function () {}) of checkBoxes() method? I cannot access the method inside the function within the method.

class Lists {
  constructor() {
    this.currentList = [];
    this.completedList = [];
  }


  createElement(
    value1 = undefined,
    value2 = undefined,
    value3 = undefined,
    checkboxCheck = ''
  ) {
    value3.append(`<li class="list-group-item p-3">
    <input type="checkbox" ${checkboxCheck}/>
      <span  class="span-item">
        ${value1}
      </span>
      <div class="float-end">
          <i class="fas fa-edit mx-2"></i>
          <i class="fas fa-trash mx-2"></i>
      </div>
      <br />
      <span class="span-time">${value2}</span>
      </li>`);
  }

  checkBoxes() {
    const checkbox = $('input[type=checkbox]');

    checkbox.off().on('click', function () {
      this.createElement(value1, value2...)
    });
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are 3 ways.

// set 'this' to 'self' outside the function
const self = this;
checkbox.off().on('click', function () {
  self.createElement(value1, value2...)
});

//use Function.prototype.bind to pass 'this'
checkbox.off().on('click', function () {
  this.createElement(value1, value2...)
}.bind(this));

//use arrow function
checkbox.off().on('click', () => {
  this.createElement(value1, value2...)
});

but i suggest you to figure out why 'this' won't work in your codes by searching.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda