Wednesday, 14 July 2021

Javascript this scope



myClassA {

    

   functionA() {

      var array = ['A', 'B'];

     // current is instance of myClassA

     var current = this;

      array.foreach(

        (item) = > {

            //this.functionB(); this  wont work as this refers current function(function is also a class, this is current function/class)

            current.functionB();

        }


     )


  }



  functionB() {

  }

}

No comments:

Post a Comment