javascript - ES6: Save variable into module scope -
i'd know if , how it's possible save next config
modules scope (think of block below 1 module):
var config = null; var mysingleton = { init: function(config) { config = config; // naming conflict! }, printconfig: function() { console.log(config); // undefined! } }; export { mysingleton };
unfortunately, naming conflict occurs. i'd need module.config = config;
.
note: i'm using es6-module-transpiler.
no. it's simple variable, , not global 1 (where accessible property of global object), shadowed , not available "namespaced".
you need utilize different name resolve conflicts, should trivial , cause no effects outside module:
var config = null; var mysingleton = { init: function(conf) { config = conf; }, printconfig: function() { console.log(config); } }; export { mysingleton };
javascript ecmascript-6
No comments:
Post a Comment