title: Passing "this" as a context to a module?
body: <p>I'm not a beginner but Javascript still often confuses me. Can someone tell me if what I am doing below is "ok"?</p>
  
  <p>In Electron, the template code to set up menus can be very long. I have a number of menus in a multi-window app and I wanted to move the menu template code from <code>main.js</code> into a module.</p>
  
  <p>So I created a new file:</p>
  
  <pre><code>const MenuTemplates = require("./app/js/menu-templates.js");  
  </code></pre>
  
  <p>and call it like this:</p>
  
  <pre><code>var mainMenu = Menu.buildFromTemplate(MenuTemplates.getMainMenuFullVersion());` 
  </code></pre>
  
  <p>Here is a truncated version of the menu template:</p>
  
  <pre><code>exports.getTimelineMenuFullVersion = function () {
      return [
          {
              label: global.appName,
              submenu: [
                  { label: 'About ' + global.appName, 
                    click: () =&gt; { showAboutWindow() } },
  </code></pre>
  
  <p>Calling the functions (e.g. <code>showAboutWindow()</code> throws an error – and that surprised me. I guess I thought that since <code>MenuTemplates</code> is loaded by <code>main.js</code>, it would have access to its methods.</p>
  
  <p>To address this I tried passing in <code>this</code> as context:</p>
  
  <pre><code>var mainMenu = Menu.buildFromTemplate(MenuTemplates.getMainMenuFullVersion(this));` 
  
  exports.getTimelineMenuFullVersion = function (context) {
      return [
          {
              label: global.appName,
              submenu: [
                  { label: 'About ' + global.appName, 
                    click: () =&gt; { context.showAboutWindow() } },
  </code></pre>
  
  <p>That didn't work – so now I am confused.</p>