Are these considered to be Javascript closures?

Viewed 117

Wanting to get something straight here...so I have 2 questions

The function below creates a closure.

function Foo(message){
    var msg = message;

    return function Bar(){ 
        this.talk = function(){alert(msg); }
    }
};

Q: Which function is the closure, Foo or Bar?
I always thought the closure to be Foo, because it closes-over Bar once Bar is returned.

Next...

Below is the definition of an anonymous function:

()();

Q: Is the inner-function within this anonymous function also a closure?

(function(){ /* <-- Is this function also a closure? */ })();
2 Answers
Related