ES6 module: re-export as object

后端 未结 2 1814
温柔的废话
温柔的废话 2021-01-01 20:30

I have moduleA which exports some functions:

// moduleA.js
export function f1() {...}
export function f2() {...}

Is there any way to re-exp

2条回答
  •  再見小時候
    2021-01-01 20:41

    file1.js

    export let uselessObject = {
      con1 : function () {
        console.log('from file1.js')
      }
    }
    

    file2.js

    import { uselessObject } from './file1.js'
    
    uselessObject.con2 = function(){
      console.log('from file2.js ')
    }
    
    export { uselessObject } from './file1.js'
    

    Index.js

    import { uselessObject } from './file2.js'
    uselessObject.con1()
    uselessObject.con2()
    

    Output

    from file1.js
    from file2.js
    

提交回复
热议问题