-2

In my component, I have one method in which I am attaching a jquery event binding.

jqueryNextDataEditableShow() {
    $('#symbolTable .editable').on('hidden', function (e, reason) {
      if (reason === 'save' || reason === 'nochange') {
        var $next = $(this).closest('td').next().find('.editable');
        if($next != undefined && $next.length == 0){
          //call that method
        }
        setTimeout(function () {
          $next.editable('show');
        }, 300);
      }
    });
  }

I have another method in the class, onSimulate().

onSimulate(){
   console.log("onSimulate Method Called");
}

I want to call it inside the jqueryNextDataEditableShow() where I put the comment mark. Problem I'm facing is, inside the function this keyword will point to the document tag or element.

Yash Jain
  • 752
  • 1
  • 12
  • 34

1 Answers1

0

Use arrow function => instead like this -

jqueryNextDataEditableShow() {
    $('#symbolTable .editable').on('hidden',  (e, reason) => {
      if (reason === 'save' || reason === 'nochange') {
        var $next = $(this).closest('td').next().find('.editable');
        if($next != undefined && $next.length == 0){
          //call that method
        }
        setTimeout(() => {
          $next.editable('show');
        }, 300);
      }
    });
  }

For more into arrow function read here -

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215