es6 modular design

// derived 
// embodiment a 
Export const name = 'Hello' 
Export the let addr = 'chengdu' 
Export var List = [l, 2,3 ]

// Second way 
const name = 'Hello' 
the let addr = 'chengdu'
 var List = [l, 2,3 ]

Export default name   // default export, only have one default Export 
Export {
   // name, 
  addr,
  list
}

// Import 
Import {name, addr, form List} './lesson-mod' 
Import name, addr {,} form List './lesson-mod' 
Import NAME2 form './lesson-mod' // only the default derived naming themselves to 
Import name, {} addr form as ADDR2 './lesson-mod' // may be utilized as rename 
console.log (name, addr, list)
// export functions, a mode 
Export default  function say (Content) {
   console.log(content)
}
export function run (){
   console.log('running')
}

// Second way 
const say = (Content) => {
  console.log(content)
}
const run = () => {
  console.log('running')
}

export {
   say,
   run
}

// import function 
Import say, {} form RUN './xx' 
say ( 'Hello Word' )
run()
// export object 
const Data = {
  code: 1,
  message: 'success'
}
of const = {
  age: 20,
  addr: 'chengdu'
}
export default {
   data,
   of the
}

//导入
import obj from './xxx'
let {data, des} = obj
console.log(obj)
console.log (data, des)
// derived class 
class Test {
  constructor () {
     this.id = 2
  }
}
export {
  Test
}

// export the default class 
Export default the Test

// write lines also 
export class Test {
  constructor () {
     this.id = 3
  }
}

// If you export the default class, the class name can be omitted 
export class {
  constructor () {
     this.id = 4
  }
}

// Import 
Import {} from the Test 'XXX' 
Import from the Test 'XXX' // Default export 

the let Test = new new the Test ()
console.log(test.id)
// whilst deriving a plurality of classes 
export class Test1 {
  constructor () {
     this.id = 3
  }
}
export class Test2{
  constructor () {
     this.id = 4
  }
}

export default class people {
  constructor () {
     this.id = 11
  }
}

//导入
import * as Mod from 'xxxx'
let test1 = new mod.Test1()
console.log(test1.id)
let test2 = new mod.Test2()
console.log(test2.id)
people the let = new new Mod. default () // Note, here can not find people, use the default 
console.log (people.id)

Guess you like

Origin www.cnblogs.com/qjb2404/p/12231101.html