简体   繁体   中英

How does the identifier resolution work in Javascript?

Can someone please explain how identifier resolution works for Javascript taking the following scenarios :

  1. A global function is called .
  2. A function inside an user defined javascript object is called .

You have to learn the context and scoping in ECMA Script to understand this. And in between is it identifier or variable?

Identifiers are normally tagged to window object. Say String() it's actually window.String().

Normally when a page loads the all the variables and functions are added as properties to the window object. The window object becomes the global context(GC) in the case of browsers. So when a global function(this is just a method nothing is there like a global function) is called the variable is just looked in the global context. And thus it'll identify the variable.

But if there is a function inside which an inner function is there then identifying a global variable will be two folds first it'll check in function scope and then in global scope. If the variable is a function variable. Then the variable will always be there in the functions execution context(EC)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM