0
   var exports = module.exports = {};
var base_url = "https://something.com:4242/";
exports.ordersummaryurl =base_url +"v1/api/stats?domain=order";

How do i do namespacing in the above code so that it has the below structure

urls.order.summary
vini
  • 4,657
  • 24
  • 82
  • 170

1 Answers1

1

Javascript does not really have a "namespace" the same way other languages such as c# does.

How do I declare a namespace in JavaScript?

Taken from that link: the best way to get the functionality that you are describing is to encapsulate the data like such:

var urls = {
    order: {
        summary: "asdfasdfasdf"
    },

    foo: function() {
    },

    bar: function() {
    }
};

To add on to this: keeping your functions in separate files and only including the "modules" that you need is another common way of achieving this.

Community
  • 1
  • 1
Dr Shenanigan
  • 163
  • 2
  • 9