concept JavaScript context in category electron
appears as: JavaScript context, JavaScript context

This is an excerpt from Manning's book Cross-Platform Desktop Applications: Using Node, Electron, and NW.js.
Listing 2.2. The main.js file for the Electron app
'use strict'; const electron = require('electron'); #1 const app = electron.app; const BrowserWindow = electron.BrowserWindow; let mainWindow = null; #2 app.on('window-all-closed',() => { #3 if (process.platform !== 'darwin') app.quit(); }); app.on('ready', () => { #4 mainWindow = new BrowserWindow(); mainWindow.loadURL(`file://${app.getAppPath()}/index.html`); mainWindow.on('closed', () => { mainWindow = null; }); }); #1 - Electron is loaded via npm #2 - mainWindow variable keeps application’s main window in JavaScript context, so garbage collection, which would close application window, doesn’t remove it #3 - Mimics UX of Windows and Linux applications — closing only application window for app quits app; on Mac OS, closing application window doesn’t close app #4 - When app is ready to run, tells main window to load index.html, and when that window is closed, sets mainWindow variable to null
Bridge the JavaScript context between Node and Chromium