Node.js JavaScript syntax

This question already has an answer here:

  • How do JavaScript closures work? 88 answers
  • What do parentheses surrounding an object/function/class declaration mean? [duplicate] 7 answers

  • This is a self invoking anonymous function. This pattern is useful when you want to hide variables from the global namespace.

    (function(){
        var foo = "foo";
    })();
    
    console.log(window.foo); // undefined
    

    Also see What do parentheses surrounding a JavaScript object/function/class declaration mean?

    What advantages does using (function(window, document, undefined) { … })(window, document) confer?

    链接地址: http://www.djcxy.com/p/1484.html

    上一篇: JavaScript函数返回函数

    下一篇: Node.js JavaScript语法