JavaScript scope and closure

前端 未结 7 1955
执笔经年
执笔经年 2020-11-28 09:21

I\'m trying to wrap my head around closures (there\'s a joke in there somewhere) and I ran across this:

(function () { /* do cool stuff */ })();
7条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 10:10

    One closures approach is to pass variables to the function:

    (function($, var_1, var_2) {
        // use JQuery, var_1 and var_2 as local variables
    })($, var_1, var_2);
    

提交回复
热议问题