// IIFE - Immediately Invoked Function Expression var KitchenApp = (function() { 'use strict'; // Isolated scope with access to Global console.log(ingredientsForPasta); var ingredientsForSauce = ['Tomato', 'Olive Oil', 'Basil']; console.log(ingredientsForSauce); }()); console.log(ingredientsForPasta); // Error: ingredientsForSauce is not defined // No access to variables defined inside de IIFE console.log(ingredientsForSauce);
(spaghetti !== undefined) { require('Recipe.' + spaghetti).cook(); } else { document.write('Y u no select a recipe?'); } }()); kitchenApp.js index.html <body data-spaghetti="Bolognese"> <script type="text/javascript" src="/assets/js/vendor/almond.js"></script> <!-- Use a build system (Gulp, Grunt, etc) to concatenate and minify files to a single one --> <script type="text/javascript" src="/assets/js/kitchenApp.js"></script> </body>