What scope is 'this' of a node.js object when it gets called at the top-level?

前端 未结 3 1942
太阳男子
太阳男子 2021-01-27 06:03

I read \"Why and how to bind methods in your React component classes?\" and grabbed the basic idea of how different is this by the scopes it gets called.

I

3条回答
  •  天命终不由人
    2021-01-27 06:24

    you should correct this line to

    const going = some.print.bind(some);
    

    Otherwise going is getting a different scope and its not an member of some object so this is undefined

    NOTE

    this refers to the current class object. And going is not a member of any class so this is undefined

提交回复
热议问题