Why are self-executing anonymous functions used in Javascript Module pattern?

前端 未结 3 2142
野性不改
野性不改 2020-12-31 17:01

In the module pattern in JavaScript \"Immediately-Invoked Function Expressions\" (also known as self-executing anonymous functions) are used as self executing functions that

3条回答
  •  离开以前
    2020-12-31 17:10

    You can define a anonymous function via named function.

    Example:

    //factorial
    (function(n){
        var self = function(n){
            //call self
            return n > 0 ? (self(n-1) * n) : 1;
        }
        return self;
    })()
    

提交回复
热议问题