ES6 module (eight)

Babel is required to run the command node environment to convert ES6 code while executing the code ES5 file
using the command directly to the code under the src directory for all ES6 ES5 convert the code to the next dist directory:

    $ babel src --out-dir dist

. 1, the export command     [ export module variable or method }
export {} | statement
Description:
 A, export command is predetermined external interface must be established with the internal module one correspondence between variables can be derived directly a value
 B, in one module, export be called multiple times to derive a plurality of values used in the form of objects m {,} n-
EG:

    // module01.js file 
    // derived directly or single function of a single variable 
    Export the let X = 10 ; 
    Export function say () { 
        the console.log ( 'say' ); 
    }; 

    // the variables and methods defined in the module from the 
    let m . 1 = ; 
    the let n- = 2 ; 
    the let Test = function () { 
        the console.log ( 'Test' ); 
    }; 

    // objects can be used deconstructed method of deriving a plurality of variable declarations or expressions 
    export {m, n, test }
     // derived variable temp variable m used in the import module receiving 
    export {x as temp}

   
2, export default command     [ default Export Data ]
export default {} | expression | anonymous function
Description:
 A, a module can only export the presence of a default ;
 B, deriving the default name is not defined generally, when introduced randomly named and does not require the use of import {} [package import data used when importing was introduced into the full import of the default variable named default ]
C, the default export can be derived using a plurality of objects in the form of data, the data export individual data values directly [or variable name can not use the expression ]
eg:

    // module01.js file 
    // Default export a module can only exist [a] derived default (usually the name is not defined, arbitrarily named when introduced) 
    Export default  function () { 
        the console.log ( 'default' ); 
    }

   
3, import command     [ imported into other modules or method variables }
import {} from "export module path"
Note:
    A, when a data export module, the module is loaded again executed upon introduction path , the file path is introduced later it is obtained from the cache.
    B, a single order mode [ import modules introduced only once; single order mode (import modules introduced only once, for later use its cache file)]
Description:
 After a, use the export command defines the module external interface, other modules this module can be loaded through the import command acquired and the corresponding derived values
 b, the data import other modules, the object variable name deconstruction simply holding one correspondence, regardless of the order in the object variable
eg:

    // module02.js file 
    // import the exported file ./module01.js m, n, test variable 
    Import {TEMP, say, m, n, test} from "./module01.js" // Import need to use a single variable {variable} wrapped 
    import} from {say "./module01.js" ; // the corresponding default derived easily take and import variable names do not need to import data {} wrapped 
    import DefaultData from "./module01.js"    // importing the default module01.js file export data [variables, methods, or objects} // import all export data module01.js module [including] the default export data 
    import * as obj from "./module01.js"    // obj object contains all the data derived module01.js module; the default name is default export data
    
    
    
    
    


4, export and import complex wording
export {} from "obtaining export module path"
EG:

    // Import module01.js module m, n and derives outwardly 
    Export {m, n} from './module01.js' ;
     // equivalent to 
    Import {m, n} from './module01.js' ; 
    export {m, n};

 

Guess you like

Origin www.cnblogs.com/nzcblogs/p/11373889.html