JavaScript function evaluating itself and calling itself at the same time

This question already has an answer here:

  • What is the (function() { } )() construct in JavaScript? 21 answers

  • Google "Immediately Invoked Function Expression" or "IIFE".

    The general syntax looks like this:

    (function(){
    // do something here
    })():
    

    Sometimes you'll see arguments passed in as well. It's basically used to wrap your code so none of your variables leak out into the global namespace.

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

    上一篇: 是否有任何理由嵌套调用$(jQuery)?

    下一篇: JavaScript函数评估自己并在同一时间调用自己