0

How can I re-define variable in external js file 'js/sample.js'?
The main idea was not touch core file and be possible to pass a new value (to var COUNT_DEFAULT) on js load from my new module.

core js example:

(function(_, $) { 

    var COUNT_DEFAULT = 2; 
    ...
nlsnmr
  • 55
  • 6

1 Answers1

0

Not sure if I understood you well, but you can do it like that.

var module = (function (myVal) {
   var COUNT_DEFAULT = myVal || 2; 
   
   return {
      val: COUNT_DEFAULT
   };
});

var defaultVal = module();
var customVal = module(45);

console.log(defaultVal);
console.log(customVal);
Serge K.
  • 5,303
  • 1
  • 20
  • 27