Monday, June 29, 2009

Javascript Best Practices 6

Reduce Globals

Try to avoid the global variable in the javascirpt code. Instead of that use the method objects.


var name = 'Jeffrey';
var lastName = 'Way';
function doSomething() {...}


Better way of writing the code.

var DudeNameSpace =
{
name :'Bala',
lastname:'Subramaniyam',
doSumething : function()
{
//do something
}
}

}