1

I'm trying simplify going through code by creating a function which works as a class for the window. When doing so, it smacks the following in my face:

windows.Main.initialize is not a function

If you have any simplicity tips regarding this, please also let me know. It means a great deal that I make clean, readable, accessible code.

main.js

const electron = require('electron');
const { app, BrowserWindow, ipcMain } = require('electron');
const windows = require('./windowmanager');

function initialize() {
    windows.Main.initialize(app);
}

// Initialize
app.on("ready", initialize);

windowmanager.js

const { app, BrowserWindow } = require('electron');
const path = require('path');

exports.__esModule = true;

function Main() {
    function Main() { };
    this.initialize = function (_app) {
        Main.app = _app;
        Main.window = new BrowserWindow({
            frame: false,
            minWidth: 800,
            minHeight: 600,
            height: 600,
            width: 800,
            show: true
        });
        Main.window.loadFile(path.join(__dirname, "../content/index.html"));
        Main.window.on('closed', () => {
            Main.app.quit();
        });
    };
    return Main;
}

exports.Main = Main;
Rob
  • 14,746
  • 28
  • 47
  • 65
Arthur
  • 23
  • 1
  • 4
  • 1
    I suspect that `require` is specifically a nodejs thing, try [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) statement instead. Also, see: https://stackoverflow.com/questions/46677752/the-difference-between-requirex-and-import-x – Nir Alfasi Apr 15 '19 at 01:34
  • 1
    `windows.Main` is a class, not an instance. – SLaks Apr 15 '19 at 01:34

0 Answers0