Function context (“this”) in nested functions

后端 未结 5 1268
名媛妹妹
名媛妹妹 2021-02-09 17:26

When you invoke a top-level function in Javascript, the this keyword inside the function refers to the default object (window if in a browser). My understanding is that

5条回答
  •  忘了有多久
    2021-02-09 18:17

    In JavaScript, when a function is invoked without an explicit context, the context is the global object. In the case of web browsers, the global object is window.

    Additionally, JavaScript has functional scope, so any variables or functions within a function are not accessible in a scope outside of that function. This is why you can't access window.innerFunc.

提交回复
热议问题