0

Not sure of the best way to phrase this question, which is why I may be unable to find the answer.

I have a terminal program, where the user selects a game config to load, which is returned as a string. This string is the name/location of a .js file, which is in itself an Object with some functions I'd like to use.

My question is: How can I use this string (file name) to open as an object and then utilise its functions?

Can provide code upon request or if necessary.

Oliver
  • 821
  • 5
  • 12
  • 28
  • [Check out this answer.](https://stackoverflow.com/a/14446538/8781351) – Trobol Dec 25 '18 at 14:38
  • @Trobol I don't believe it applies as that is opening a text file and will provide the text as a string. I'd like to use a .js file path and handle that file as the object/class it defines within itself. – Oliver Dec 26 '18 at 09:21
  • Is this running in Nodejs or the browser? – Trobol Dec 26 '18 at 15:33
  • You said `"open as an object and then utilise its functions"`; does that file include Javascript code you want to execute or is it just config as JSON? Can we assume you run this with Node.js? Please clarify your question by using "edit" below your post. – try-catch-finally Dec 26 '18 at 15:52
  • 1
    I think there are several points you need to clarify: 1. What's the runtime, nodejs or browser or anything else? 2. What's your concern, "how to achieve it technically" or "is it secure to load abitary js file"? – obfish Dec 26 '18 at 15:56

0 Answers0