0

Say I have a file.js with a lot of functions and code, which I want to seperate into different files.

What would be a best-practice structure to do this? And I think that I'm talking about creating an object. But I'm not sure..

Thanks in advance,

Nick

  • Duplicate: http://stackoverflow.com/q/4576581/221061 – Chris Laplante Mar 22 '12 at 18:51
  • 1
    Why do you want to separate the file? Also, it's likely that such a big file contains inconsistent indentions. Copy-paste the contents at http://jsbeautifier.com/, to nicely format the code. – Rob W Mar 22 '12 at 18:52
  • I am building an game engine and it's single file but the its exceeded the 2000 lines of code, and I want to clean it up a bit / seperate code to make it easier to edit / upgrade. – Nick Verheijen Mar 22 '12 at 19:33

1 Answers1

2

JavaScript does not have a simple method of including other JavaScript files. Generally I create several files and include them individually for testing. For production I use ant to concatenate the files and apply something like the closure-compiler and/or yui compressor on the output. Something like this may serve as a good starting point.

Alex Barker
  • 4,316
  • 4
  • 28
  • 47