0

My code needs to handle several scenarios that involve importing specific files. The info for each scenario is stored in a JavaScript object. I would like one property to reflect the import filename and another property to reflect the import filepath. I also want to avoid having to update the filename in two places each time I create an object for a new scenario

Current Setup

    // Cross-Scenario Variables
    static inputFolder = './resources/xl-data/'

    // Import Scenarios
    static scenario = {
        scenario01: {
            scenarioDescription: "Scenario 01",
            importFilename: "scenario01.xlsx",
            importFilePath: this.inputFolder + "scenario01.xlsx",
        },
        scenario02: {
        },
        // etc
    }

Ideal Setup

    // Cross-Scenario Variables
    static inputFolder = './resources/xl-data/'

    // Import Scenarios
    static scenario = {
        scenario01: {
            scenarioDescription: "Scenario 01",
            importFilename: "scenario01.xlsx",
            importFilePath: this.inputFolder + **this.**importFilename,
        },
        scenario02: {
        },
        // etc
    }

I am already using the 'this' keyword to access a global property. Is there another keyword I could use to refer to the innermost of several nested objects?

I want some way to refer to the importFilename property from inside of the scenario01 object.

KHeidtman
  • 11
  • 2
  • Use a factory function as a helper: `… scenario01: makeScenario(this.inputFolder, "Scenario 01", "scenario01.xlsx"), …` – Bergi Mar 09 '23 at 20:59

0 Answers0