View Single Post
  #2 (permalink)  
Old November 10th, 2015, 02:25 PM
lewisje lewisje is offline
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to lewisje
Lightbulb

It means that the Function constructor always creates functions in the global scope, while a function expression inside another function creates a function in that other function's inner scope; they're logically equivalent because alert is a global function and this is determined by execution context, not scope.

If the second example had created a variable named "alert" inside the outer function then the "alert" inside that Function constructor would still refer to the global alert.

If the first example had created a variable named "alert" inside the outer function then the "alert" inside that inner function expression would refer to the variable, and not the global alert.
Reply With Quote