简体   繁体   中英

Why is this passed to a anonymous function: “undefined” != typeof global ? global : “undefined” != typeof window && window

!function(){
   function body
}("undefined" != typeof global ? global : "undefined" != typeof window && window)

The parameter evaluates to "window" in my browser. There are two things I don't understand: 1) when will "global" be defined? And when will "global" and "window" be both "undefined"? 2) what is the purpose to pass "window" or "global" or a Boolean false into an anonymous function which has no parameter?

In a browser there is an intrinsic object called window, while in other environments such as Node.js there is an object called global. This code evaluates to either global or window depending on which one is defined, or to false if none is. As for passing an argument to a function that takes no argument makes no sense unless the object arguments is used inside.

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