C
Chris Smith
'Morning,
Within the next few months, I'm going to embark upon a comparatively
rather large base of JavaScript code to be called from a web browser
environment. Not too awfully huge, but probably between 10K and 15K
LoC. Having seen only the kinds of scripts that support interactive web
pages, I'm dreading trying to stretch JavaScript that far. Has anyone
here done something like this, and want to share some experience?
In my feeble experience, I've adopted a few stylistic tendencies that I
wanted to run by those of you with more experience, to see if you
foresee problems. Here are a few questions:
1. JavaScript books I've seen all seem to define object methods as
functions with a global name, and then assign them into an object as a
function. I'm concerned that this leads to a lot of global names. I've
been looking at using anonymous functions as an alternative, as in:
/* constructor */
function Foo()
{
/* methods */
this.foo = function()
{
...
}
this.bar = function(baz)
{
...
}
/* fields */
this.kazoo = this.foo();
this.kazam = null;
}
That way, I only define one global name, and don't end up with ugly
temporary names that only exist to be used in assignments for object
methods.
2. What do you normally do with methods that are only intended for
internal use within an object, and not to be called from the outside
world? Do you tag them somehow (I've been looking at a leading
underscore... I generally dislike these kinds of identifier tags, but in
the absence of language support for visibility, I might be convinced to
adopt one), or merely provide separate documentation of publis
interfaces for each object and don't include them there?
3. How do I combine lots of JavaScript source files into a single web
page. Having zillions of script tags seems hokey, but I can't find a
way to include one JavaScript source file from another, so it looks like
everything does need to be included directly from the HTML source. Any
other solution? Does this mean that the page will wait on the loading
of this large amount of JavaScript before it finished its own loading?
I'm considering solutions like having zero-size frames in a frameset
that load other pages with JavaScript code in them, to avoid holding up
the loading of functional pages. Any other ideas?
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Within the next few months, I'm going to embark upon a comparatively
rather large base of JavaScript code to be called from a web browser
environment. Not too awfully huge, but probably between 10K and 15K
LoC. Having seen only the kinds of scripts that support interactive web
pages, I'm dreading trying to stretch JavaScript that far. Has anyone
here done something like this, and want to share some experience?
In my feeble experience, I've adopted a few stylistic tendencies that I
wanted to run by those of you with more experience, to see if you
foresee problems. Here are a few questions:
1. JavaScript books I've seen all seem to define object methods as
functions with a global name, and then assign them into an object as a
function. I'm concerned that this leads to a lot of global names. I've
been looking at using anonymous functions as an alternative, as in:
/* constructor */
function Foo()
{
/* methods */
this.foo = function()
{
...
}
this.bar = function(baz)
{
...
}
/* fields */
this.kazoo = this.foo();
this.kazam = null;
}
That way, I only define one global name, and don't end up with ugly
temporary names that only exist to be used in assignments for object
methods.
2. What do you normally do with methods that are only intended for
internal use within an object, and not to be called from the outside
world? Do you tag them somehow (I've been looking at a leading
underscore... I generally dislike these kinds of identifier tags, but in
the absence of language support for visibility, I might be convinced to
adopt one), or merely provide separate documentation of publis
interfaces for each object and don't include them there?
3. How do I combine lots of JavaScript source files into a single web
page. Having zillions of script tags seems hokey, but I can't find a
way to include one JavaScript source file from another, so it looks like
everything does need to be included directly from the HTML source. Any
other solution? Does this mean that the page will wait on the loading
of this large amount of JavaScript before it finished its own loading?
I'm considering solutions like having zero-size frames in a frameset
that load other pages with JavaScript code in them, to avoid holding up
the loading of functional pages. Any other ideas?
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation