Closures mean that in JavaScript, intrinsic functions always have access to the arguments and variables declared in the external function in which they are located, even after their external functions are returned (end-of-life).
At the same time, to reduce the pollution of global variables
// reduce the pollution of global variables function outer () { var a = ten; function inner () { alert (a+ +) ; } return inner; } // alert (a);//a is a local variable that cannot be accessed in this var test = outer (); // using closure access a expands the scope of a
Simple module
varUser = (function(winobj) {vari = 111; varJsonobj = winobj.$ = { "Add":function() {alert (' Add user ' +i); }, "Delect":function() {alert (' Delete user '); }, "Update":function() {alert (' Modify user '); } } returnJsonobj; }) (window); User.add (); varCategory = (function(){ vari = 222; return{ "Add":function() {alert (' Add product Category ' +i); }, "Delect":function() {alert (' Delete Product category '); }, "Update":function() {alert (' Modify Product type '); } } })(); Category. Add ()
The first module is the addition, deletion of users, and other actions
The second is to do a simple pruning on the basis of the first, and make out the module of the commodity kind
07.30 "JavaScript"-closures and simple modules