Return a function from the anonymous wrapper?

Posted by sabithpocker on Stack Overflow See other posts from Stack Overflow or by sabithpocker
Published on 2012-06-26T03:06:25Z Indexed on 2012/06/26 3:15 UTC
Read the original article Hit count: 197

Filed under:
|

I am trying to undrstand the code

for(var i = 0; i < 10; i++) {
    setTimeout((function(e) {
        return function() {
            console.log(e);
        }
    })(i), 1000)
}

from here http://bonsaiden.github.com/JavaScript-Garden/#function.closures

I understood this method :

for(var i = 0; i < 10; i++) {
    (function(e) {
        setTimeout(function() {
            console.log(e);  
        }, 1000);
    })(i);
}

Can anyone please help me by explaining the first one?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery