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)
export
出去的对象,其本身的引用是不能改,但是其内部的属性是可以修改的。你
export
Just create an object specifically for this type of shared variable.