-1

I need to code a module pattern instantiated in a window property. What would be the best way of doing that?

var widget = (function(){


}());
Abel Abad
  • 147
  • 1
  • 2
  • 13
  • It's not clear what you're asking. Can you give more details? The code you've quoted is correct as far as it goes. What you do next depends a lot on what you're looking to achieve. – T.J. Crowder Jul 31 '16 at 11:11
  • Every variable you declare in your everyday browser should be accessible through `window`. E.g. `var foo = 3; window["foo"] // returns 3` – Daniel Cheung Jul 31 '16 at 11:19
  • it is a question in a test. "Create a module pattern instantiated in a window property". – Abel Abad Jul 31 '16 at 11:36

1 Answers1

0

The new best practice in JS world is to use UMD or es6 modules with rollup library and/or babel.

Short answer to your question

(function(global){
    global.widgetName = {};
}(this));
stac
  • 378
  • 1
  • 4
  • 10