0

when I have a method m of an object o with one variable that needs to be handed a FormData-Object and inside the o object definition I want to define another method called n that uses the method m how can I solve the following reference problem:

o class {

    n(){
        $("#someForm").submit( 
        var data = new FormData(this); /* here the this keyword is the form */
        this.m(data); /* here the this keyword should referece back to the instance of the object*/
        );
    }

    m(formDataObj){...}

}

how can I make n() work?

Nighel
  • 71
  • 12
  • See the linked question's answers. Specifically in your case, you could use `var instance = this;` in `n` prior to the submit call, and then use `instance.m(data);` Or you could use an arrow function (ES2015+) for the submit handler and use `e.currentTarget` or `e.target` (since this is submit) to reference the form. – T.J. Crowder Mar 25 '17 at 17:43
  • Side note: The code in the question has at least two syntax errors: `o class` and you've forgotten to use a function around the lines within the `submit`. – T.J. Crowder Mar 25 '17 at 17:43

0 Answers0