Created
February 11, 2015 12:26
-
-
Save davidhund/b1a62c071526202541ec to your computer and use it in GitHub Desktop.
Exposing a Global Browserify module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* NOTE: I am new at this and probably miss something obvious :-) | |
* | |
* What I'd like to do is the following: | |
* - Using the Revealing Module Pattern.. | |
* - .. combined with Browserified modules.. | |
* - .. to expose (not export) `myModule` globally in main.js (-> bundle.js).. | |
* - .. and to use it in the browser e.g: myModule.init() | |
* | |
* How do I (best) end up with a global `myModule`?? | |
*/ | |
// E.g. take the following | |
/** | |
* main.js | |
*/ | |
var util = require('someUtil'); | |
var libb = require('someLib'); | |
// Revealing Module | |
var myModule = (function( win, doc, undefined ){ | |
'use strict'; | |
// 'Private' stuffz | |
var _private = { | |
init: function(){ | |
console.log('_private.init()'); | |
} | |
}; | |
// 'Public' stuffz | |
var _public = { | |
init: _private.init | |
}; | |
return _public; | |
})( window, document ); | |
// NOW: when I do the following (in e.g. Devtools) | |
// > console.log(myModule); | |
// > uncaught ReferenceError: myModule is not defined | |
// So how should I expose `myModule` as a global? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment