Show love to the object literal
Thursday, February 16th, 2006German Visitors: Zur deutschen Version gehts hier – auf dem Blog von Jens Grochtdreis
If you are just getting your teeth into JavaScript, or if you used it in the past and re-discovered it in the wake of the AJAX craze you might have been baffled by scripts that come in a new syntax.
While older copy and paste scripts looked like this:
var commonSense=null; var standardsCompliance="50%"; function init(){ // code } function doStuff(){ // code } function doMoreStuff(){ // code } |
Newer scripts inside tutorials tend to look like this:
awesome={ commonSense:null, standardsCompliance:"50%", init:function(){ // code }, doStuff:function(){ // code }, doMoreStuff:function(){ // code } } |
The new syntax is called the object literal and is pretty close to sliced bread. Here is why: (more…)