JavaScript-ECMAScript the module

  •  function

Function is to achieve a set of statements specific logic package, JS scope is also based on function, so it can function as a modular nature, it is also a way of beginning a modular implementation.

That reference is to call the function module, contamination of the disadvantages of global variables, variables conflict.

 

  • Objects

 

 

The above function is encapsulated in an object, i.e. a reference block corresponding file attribute on the referenced objects, such as: myModule.func1 (), by its object name (module name) to avoid pollution of global variables, but there are safety issues, such as: external free to modify the interior of the module attributes and methods.

  • Immediately execute the function

 

 

On the basis of the above object, immediately execute the function performed by the package, can solve the pollution of global variables, properties and methods to prevent the internal modules are external modification, which is the basis of the current mainstream module specification.

Guess you like

Origin www.cnblogs.com/cuner/p/12499798.html