dakrauth
11/16/2011 - 9:48 PM

Javascript coding guidelines

Javascript coding guidelines

// Defining variables
var my_array = [1,2,3]; 
var foo      = ["abc", "def"];
var what     = "saywhat?";
var temp, i, j;

// for loops 
for(var i = 0, j = my_array.length - 1; i < j; i++, j--) {
    temp        = my_array[i];
    my_array[i] = my_array[j];
    my_array[j] = temp;
}

// function invocation
console.log(ar);
switch(what) {
    case "def":
        do_something();
        break;

    case 'abc':
        do_something_else();
        break;

    case 'saywhat?':
        console.log("Please be careful will fall throughs");
        // ***********************************************************
        // !!! NOTE -- Explicit fall through
        //
        // My very good reason for using a fall through is...
        // ***********************************************************
        
    default:
        console.log("Huh?");
}

if(true) {
    // it's true
}
else {
    // it ain't so
}

var my_func = function(param_1, param_2, param_3) {
    return;
}


my_func.apply(
    this,
    'Hello, world',
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod',
    'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim'
)


$('p span', this)
    .chain('foo')
    .chain('bar')
    .chain('baz');