search

Home  >  Q&A  >  body text

How to share objects between es6 modules

Use es6 moudle to organize business modules. There are three modules a, b, and c. There is object obj in module a, and export {obj}, both module b and module c are import {obj}, then the b module needs to change the value of obj in the a module;
The traditional way is to directly modify the global variable, and the object exported by the a module in es6 is read-only for the b module. This How to solve the problem (without broadcasting)

阿神阿神2802 days ago716

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-19 10:49:01

    export出去的对象,其本身的引用是不能改,但是其内部的属性是可以修改的。
    exportJust create an object specifically for this type of shared variable.

    reply
    0
  • Cancelreply