How should I go about a long JavaScript file using the module pattern? -


i learning design pattern in javascript, , i'm going use module pattern. i'm puzzled 2 things.

1 - if create plugin, can use module pattern, , have private , public methods/variables. if have full javascript file, don't need private , public methods, since 1 part of program has nothing part. what's point of private , public methods?

2 - since javascript file long, should have nested module's? how should go full file of javascript?

(1)

when javascript files loaded, scripts in files in 1 file. script in 1 file can access (read, update, delete) global variables in other files. there lot of questions on this, can search those.

of course, "one part of program has nothing part", in case in team many members, each works on part of system (or in cases, file). then, there chance 1 person accidentally changes variables created person. kinds of error quite easy detect. if can modularize script, can avoid kinds of error altogether.

(2)

you can go slow. while writing code complete requirements, try recognize parts of code can separated modules (or nested modules). them put them other files.

you should creative , careful while doing so. code might grow fast , things out of control quickly.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -