0

I have the following code in a .js file. How do I add new functions within the same namespace from a different .js file?

if ("undefined" == typeof(sample)) {
    var sample = {};
}

sample = {
    foo : function () {

    },

    bar : function () {

    }
};
Adrien Hingert
  • 1,416
  • 5
  • 26
  • 51
  • You really shouldn't: each file should be a module and you should import them as needed, to keep things clean. JS doesn't benefit much from classical namespaces. – ssube Apr 23 '15 at 20:09
  • Didn't you just ask this -> http://stackoverflow.com/questions/29831960/javascript-varibles-across-functions – adeneo Apr 23 '15 at 20:12
  • Oh, okay, this is a little different. `sample.newFunc = function() {...` – adeneo Apr 23 '15 at 20:13

0 Answers0