473,842 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structuring Javascript code

I hope you don't mind trivial questions. I only ask them after failing to
find answers in my book and on the web...

Can I split Javascript code into separate js files which reference each
other (hierarchically )? For instance, can I put core functions in a library
file and refer to them from other script files (like: $ïnclude "core.js").

TIA
Tom
Feb 20 '08 #1
4 1570
On Wed, 20 Feb 2008 17:40:11 +0100, Tom de Neef wrote:
Can I split Javascript code into separate js files which reference each
other (hierarchically )? For instance, can I put core functions in a
library file and refer to them from other script files (like: $nclude
"core.js").
You can separate javascript into separate files that are read in with the
<scripttag. You need one tag per javascript file to include.

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

(There are some tricks make one javascript file to include the others, but
that is often regarded as 'dirty' at best and unreliable at worst.)

Feb 20 '08 #2
On Feb 20, 8:40 am, "Tom de Neef" <tden...@qolor. nlwrote:
I hope you don't mind trivial questions. I only ask them after failing to
find answers in my book and on the web...

Can I split Javascript code into separate js files which reference each
other (hierarchically )? For instance, can I put core functions in a library
file and refer to them from other script files (like: $ïnclude "core.js").
There are quite a few "module loader" systems out there that allow
building dependencies like this. I don't use such a system. I just
manually list them in the page like this

<script type="text/javascript src="core.js"></script>
<script type="text/javascript src="app.js"></script>

I think the module loaders encourage making many HTTP requests to the
server and that is a bad idea. It is better to have a build system
that aggregates the various JavaScript development files into
production files with the whitespace removed etc.

Peter
Feb 20 '08 #3
"Peter Michaux" <pe**********@g mail.comschreef in bericht
news:0b******** *************** ***********@o10 g2000hsf.google groups.com...
On Feb 20, 8:40 am, "Tom de Neef" <tden...@qolor. nlwrote:
I hope you don't mind trivial questions. I only ask them after failing to
find answers in my book and on the web...

Can I split Javascript code into separate js files which reference each
other (hierarchically )? For instance, can I put core functions in a
library
file and refer to them from other script files (like: $ïnclude "core.js").

<script type="text/javascript src="core.js"></script>
<script type="text/javascript src="app.js"></script>

So, the HTML will bind it all together. That is fine: a function defined in
"core.js" can be referenced in "app.js" and within the HTML it will work
together.

That does not solve the problem of how to test "app.js" without the HTML, if
it calls a function declared in "core.js". Or do you never test the script
standalone? In my editor (Antechinus) standalone testing is an option.
Tom
Feb 20 '08 #4
On Feb 20, 10:43 am, "Tom de Neef" <tden...@qolor. nlwrote:
"Peter Michaux" <petermich...@g mail.comschreef in berichtnews:0b* *************** *************** ***@o10g2000hsf .googlegroups.c om...
On Feb 20, 8:40 am, "Tom de Neef" <tden...@qolor. nlwrote:
I hope you don't mind trivial questions. I only ask them after failing to
find answers in my book and on the web...
Can I split Javascript code into separate js files which reference each
other (hierarchically )? For instance, can I put core functions in a
library
file and refer to them from other script files (like: $ïnclude "core.js").

<script type="text/javascript src="core.js"></script>
<script type="text/javascript src="app.js"></script>

So, the HTML will bind it all together. That is fine: a function defined in
"core.js" can be referenced in "app.js" and within the HTML it will work
together.
You are correct. All the scripts are evaluated in the same global
namespace.
That does not solve the problem of how to test "app.js" without the HTML, if
it calls a function declared in "core.js". Or do you never test the script
standalone? In my editor (Antechinus) standalone testing is an option.
I suppose the editor should be able to be told which scripts to "load"
when testing a particular script.

Peter
Feb 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1319
by: Milla | last post by:
Hi guys I need some advice on how to best structure my forms and php code into separate files, and how to move variables and form content between them. I'm sure this is really standard stuff and it must have been solved over and over already. This is the flow of what's happening and how it's been structured so far:
4
1519
by: iv | last post by:
Hello, I'm busy with a large application and feel it would eas my work if I can specify dependencies on the granularity of packages, rather than modules and classes. Eg: - By convention I do the one class per file thing. SO in python this means one class per module - naming classes after their modules. (this helps with version control, and several other little irritations, for example)
14
1866
by: Steven T. Hatton | last post by:
Is there a more or less accepted authority describing how to structure a project? I know Julie has asked about namespaces. That is certainly a part of my question, but I want to know about the whole picture. If such a thing doesn't exist, then would someone with enough name recognition to have an influence please decree such a guideline. I'd be happy to simply be able to say my project is organized in accordance with the ...
1
1776
by: jmgro | last post by:
I need help in structuring a 200 question survey. Each question has three responses, and I want all 200 questions displayed at the same time with the user using the scrollbar to go down. What is the best approach?
1
1067
by: Simon Harris | last post by:
Hi All, I work in a team of three developers. 99% of our work is developing 'applications' for our organisations Intranet - mainly whats become known to us as e-employee apps, such as sickness/holiday reporting/authrisation, handling the new starter/leaver processes, etc...the list goes on. Up to recently, we have been developing in 'classic' ASP, storing all apps in subdirectories of there own.
3
1200
by: arun.hallan | last post by:
Hi, I need some structuring help. I have a set of data, in the form of an arraylist of objects. Each object is the same, and can be treated as a generic object which gets and sets properties. I want to display this in a datagrid - which is not too hard. I've done this by mapping the object data to a datatable, and then
7
1733
by: JohnGoogle | last post by:
Hi, I'm new to Visual C# and I am looking for guidance with structuring projects. I am wanting to develop a DLL assembly which will contain all my common classes which will be used by various projects. During development of this DLL assembly I have decided to have a second project which will be a console application whose entire job is to run code to test the classes to iron out bugs etc.
2
2011
by: Susanne West | last post by:
hi group. i'm tackling a bigger project that will use mod_rewrite to patch a series of urls into a master php-script. this script builds the page framework that contains a series of elements that remain on every page. only a center part (a <div>) is filled with different contents, depending on how the page is called (= mode of the page). the point is, there are quite a few (approx 20) different 'modes' for the center part to be filled...
0
1006
by: TC | last post by:
When I'm debugging code and a runtime error occurs, Visual Studio usually gives me a specific error message and identifies the line which caused the error. Sometimes, however, it does not do those things. Instead, it gives me the generic error message "Exception has been thrown by the target of an invocation" and identifies a line higher up in the call stack. When this happens, it can be difficult to diagnose the cause of the runtime...
0
9875
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10674
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9454
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.