0

I have dictionaries of strings in separate JavaScript files.

//a.js
Dict = {
    Something = "foo",
    Else = "bar"
}

//b.js
OtherDict = {
    Fell = "foo",
    End = "d"
}

Some of the strings are the same in various dictionaries, and I'd like to define them once and point at them in multiple dictionaries.

Dict = {
    Something = Strings.Foo,
    Else = "bar"
}

OtherDict = {
    Fell = Strings.Foo,
    End = "d"
}

I tried using jQuery, but it didn't seem to successfully include the file. How can I include one js file in another and then reference it in the declaration of a dictionary?

EDIT: The problem was that I made a typo in one of the filepaths. Everything's fine now.

Community
  • 1
  • 1
trekkieyk
  • 345
  • 2
  • 12
  • What exactly do you mean by "dictionary" here? – Pointy Aug 20 '15 at 19:25
  • if the files are been loaded into the same document you don't need to reference the file in the other. It's all part of the global scope. – Typo Aug 20 '15 at 19:30

1 Answers1

0

Unless you're using ECMA-Script 6 and modules, JavaScript code files can't include other ones. You still need to use <script> elements.

If you're using ECMA-Script 6, you can use modules:

import script1 from "js/script1.js";

// Define more stuff here
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206