Basic query on passing this to a function

后端 未结 4 672
长发绾君心
长发绾君心 2021-01-26 00:50

I am trying to understand JavaScript this better.

function foo() {
    console.log(this);
}
// normal function call
foo(); // `this` will refer to `window`
         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-26 01:33

     var that = this;
     function foo(that){
       console.log(that):
     }
     foo();
    

    foo() parameter is missing.

    so function foo(that) will be undefined.

    To make it work

     foo(that)
    

提交回复
热议问题