Looking for pure JavaScript answers please.
Using IIFE for a JavaScript game. Actually multiple games on multiple webpages. Suppose there is a common piece of code that needs to be used by all of these games. Say for example, a diceroller; 1d20, 3d6, etc.
What is the right way to do this? Should the IIFEs all be set to the global with unique names? I worry about setting to the global (perhaps I am too worried about that).
Does the diceroller need to be passed into the game IIFE? How to do this properly?
npmorbower, package your source into a small testable module and then declare your dependency in your main project. then you should use something likebrowserifyorwebpackto include your module inside your code,var diceRoller = require('diceRoller');or in ES6import diceRoller from 'diceRoller'requireviarequire.jsorbrowserify..., amd, or the new ES6 stuff withimport) and you'll have module in your browser !