ciplogic.com
Live with grace. Write superb software.

In this small series, I'm going to start explaining how to do JavaScript debugging, namely bug tracing at the advanced level, since I can't seem to find tutorials except how to actually run the debugger itself.

So in order to start, let's build first an utility class that we'll use in several places, the onceMany utility function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(function() {
 
if (!window.ciplogic) {
    ciplogic = {};
}
 
ciplogic.onceMany = function(once, many) {
    var firstGenerated = false;
    return {
        next : function() {
            if (firstGenerated) {
                return many;
            } else {
                firstGenerated = true;
                return once;
            }
        }
    }
};
 
})();

As you can see at line 3, we will keep everything in the ciplogic namespace. From this moment on, we can call:

1
2
3
4
5
6
var comma = ciplogic.onceMany("", ", "),
    result = "";
 
for (var i = 0; i < arguments.length; i++) {
    result += comma.next() + parseArgument(arguments[i]);
}

And we don't need to keep a new array for join operations.

 

Disqus Comments

comments powered by Disqus

Germanium

The one to rule them all. The browsers that is.

SharpKnight

SharpKnight is an Android chess game.

MagicGroup

MagicGroup is an eclipse plugin.