0

I would like to use global varibales whenever possible

For example I have a global js called global.js where I define a global util class

var glbalUtils = {
   strint: {
       capitalize: capitalize,
       format: format // similar to python format
   },

   number: {
       ordinate: ordinate
   }
}

function capitalize(str){
   // implement capitalize. All functions have definitions 
}

I want globalUtils to be available throughout in code base.

These are things I feel are should be available anyway. The only other option is to extend prototype, which I have read is for suckers.

So what exactly is wrong with method of coding?

  • what is your requirement ? dont understand – Wasiq Muhammad Aug 06 '16 at 18:43
  • Check this http://stackoverflow.com/a/6989918/5102631 – Ayan Aug 06 '16 at 18:44
  • What would something be wrong with that? – Slava Knyazev Aug 06 '16 at 18:47
  • 1
    You shouldn't be using globals whenever possible, you should be using them **only** when it's your only option, or a workaround would be ridiculously complex. Pass in any variables you need! – Carcigenicate Aug 06 '16 at 18:53
  • 2
    You've added `globalUtils` (sic) to the global namespace, which doesn't seem that unreasonable--although ES6 modules provide a far better alternative--but you've also added `capitalize` to the global namespace, which I doubt you want to do. –  Aug 06 '16 at 18:57

0 Answers0