Tips for managing lots of code?

My project seems to be getting bigger and bigger, and some of my classes are thousands of lines long. It’s too difficult to view them every time I want to make changes.

I find that JavaScript is not as easy to lay out as some other programming languages. So when the classes go through a few thousand lines, I have trouble reading.

I tried to split it into several files, but then you break classes, which seems wrong. For example, if each method in a class uses a global variable, you can find the global variable in only one of the files in this class.

Also, if I want to use JavaScript code from 100 different .js files, I get something like this ...

<script type="text/javascript" src="Scripts/classes/Node.js"></script>
<script type="text/javascript" src="Scripts/classes/Queue.js"></script>
<script type="text/javascript" src="Scripts/classes/DblyLinkedList.js"></script>
  .... 97 more lines like this

Although, I thought there might be something that I can do ...

<script type="text/javascript" src="Scripts/.../*.js"></script>

or something like that ... is that right?

Does anyone have any tips on managing code when it reaches its extremes?

Tips for clearing JavaScript code will also be helpful.

+3
source share
7 answers

Ripping JS into separate files has some significant drawbacks, mainly because you force web browsers to make a separate request for each file.

Have you taken a look at keeping all your files separate, but creating a “one set” for each project containing only the necessary files? This can be automated using a script.

SitePoint : http://www.sitepoint.com/blogs/2007/04/10/faster-page-loads-bundle-your-css-and-javascript/

+2
  • (a) [ ],
  • (b) " " ( - IDE Javascript , , Emacs, Vim, Eclipse TextMate ),
  • (c) <script> " " , " ".

, , , (SVN, Mercurial ..), : - (.

+1

, . YSlow .

+1

, , , .

-, , . , - .

. 2 - 2 , ( , )

{ , , )

, , .

... , .

0
<script type="text/javascript" src="Scripts/.../*.js"></script>

, , , , , .

, - , . Eclipse Spket / Aptana, , , - , .

edit: js . , . HTTP-. .

0

AvatarKava . . , . " " . , ? , ? , .

0

...

, . , .

if (foo == undefined)
   var foo

, , , . , grep, IDE intellisense.

. 100 "classes" . , , , .. , .. include ... collections.js, . , , , , .

0

Source: https://habr.com/ru/post/1709045/


All Articles