Archive for the 'Javascript' Category

Javascript Style Guide from Google

It is always nice to have a style guide that is ready to use. If you click on the arrows you might find some valuable information.

http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml

Adding Tiger Stripes to Tables with jQuery

I have been a Prototypejs fan for a long time, but I finally got around to work with jQuery and it is truly an amazing framework.

In the old days when I would want to add stripes to my tables (with a class named tiger), I would have done something like this.

Doing it old school

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
window.onload = function () {
    var i, n, tables, table, trs, tr;
    tables = document.getElementsByTagName("table");
    for (i = 0; (table = tables[i]); i++){
        if (/\btiger\b/.exec(table.className)){
            var tbodys = table.getElementsByTagName("tbody");
            if (tbodys.length == 1){
                trs = tbodys[0].getElementsByTagName("tr");
            }else{
                trs = table.getElementsByTagName("tr");
            }
            for (n = 0; (tr = trs[n]); n++){
                tr.className += (n % 2 == 0) ? " alternate" : "";
            }
        }
    }
}

With jQuery magic

1
2
3
$(document).ready(function() {
    $("table.tiger tr:even").addClass("alternate");
});

Pretty simple, right?

Douglas Crockford On Javascript

Here are the latest installments from Douglas Crockford.

If you have seen some his other lectures on Javscript, then you can probably skip through some of them. If you don’t know him, then I can guarantee that you will learn something very interesting about javascript.

Volume One: The Early Years (Monday, January 25, 2010)

Chapter 2: And Then There Was JavaScript (Friday, February 5, 2010)

Act III: Function the Ultimate (Wednesday, February 17, 2010)

Episode IV: The Metamorphosis of Ajax (Wednesday, March 3, 2010)

Part 5: The End of All Things (Wednesday, March 31, 2010)

Next Page »