Archive for the ‘Organizing Code’ Category

Show Love to the Object Literal

February 21st, 2006 by Aaron N.

Another snippet via Ajaxian:

A Javascript tip from Chris Heilmann, who reckons the object literal is “pretty close to sliced bread”. Replace:

var commonSense=null;
var standardsCompliance=“50%”;
function init(){
// code
}
function doStuff(){
// code
}
function doMoreStuff(){
// code
}

with the object literal form:

awesome={
commonSense:null,
standardsCompliance:“50%”,
init:function(){
// code
},
doStuff:function(){
// code
},
doMoreStuff:function(){
// code
}
}

Read the rest of this entry »

Javascript Namespace Solutions

February 16th, 2006 by jlau

In the past two weeks, I have run into live site issues due to namespace problems (javascript functions being named the same) in our javascript files.

I came across this article about versioning. It mentions some solutions for this problem.
Read the rest of this entry »

Dynamic Script Loading

February 14th, 2006 by Aaron N.

Over at webreference.com they have an article about loading javascript dynamically as you need it. Basically, you would have a server side applet that was the gateway to all your scripts. This you could query and it would return the javascript that you required to run your app.

I’ve been thinking along these same lines since I read about jspkg, which looks like it does exactly this. Developers could write large javascript libraries without worrying about browser load for specific apps. We could organize this code into convenient libraries that can be shared among us, and then when we develop an app, we just include the functions we require. Thoughts?

Some examples of 3rd party scripts in use on Download.com

February 9th, 2006 by Aaron N.

Eric’s comments regarding the use of 3rd party libraries and my response got me thinking that I should post a few examples of what we’ve been doing at Download.com. My only caveat is that I’m probably the person most responsible for this policy as I push for functionality that necessitates their use. Read the rest of this entry »

jspkg - Javascript Package Loader

February 8th, 2006 by Aaron N.

This looks very promising:

jspkg is a package loader for Javascript, based on pluggable loaders for locating and loading scripts into a client-side Javascript application. It is designed to work best with unobtrusive Javascript libraries, but doesn’t impose any methodology or design on its users.

Examples:

http://jspkg.sourceforge.net/examples/onlyrequired/test.html

more: http://jspkg.sourceforge.net/