jQuery/JavaScript “this” pointer confusion

前端 未结 7 723
余生分开走
余生分开走 2020-11-29 02:44

The behavior of \"this\" when function bar is called is baffling me. See the code below. Is there any way to arrange for \"this\" to be a plain old js object in

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 02:51

    this.bar();  // when called here, "this" is the foo instance
    

    this comment is wrong when foo is used as a normal function, not as a constructor. here:

    foo();//this stands for window
    

提交回复
热议问题