When answering another question, I used this template to call a function recursively:
(function() {
who worked. I got the feedback that function naming also worked:
(function func() {
However, with this technique, window.func is undefined , which came as a surprise to me.
If I put it simply, my question is: why is the following true?
function a() {} typeof window.a; // "function" (function b() {}) typeof window.b; // "undefined"
b is still available inside b . So it seems that ( ) creates a different scope, but this cannot be because only functions create a different scope, and I just wrap it inside ( ) .
So why doesn't wrapping a function inside ( ) put a function in a global object?
source share