Blog Archives

Left or Right Curly Braces

Should you put your curly braces on the left or right?

function foo(){
    //My curly brace is on the right.
}

function bar()
{
    //My curly brace is on the left.
}

Read the rest of this entry

Advertisements

The JavaScript Object Literal

I have been really trying to beef up my JavaScript skills lately.  One really interesting aspect from this experience is how cool I find the object literal.

You can use it to create really any kind of data structure you desire.  It can hold the primitive types like strings and numbers, it can hold objects like arrays or other object literals, and it can store functions.  I created a fiddle at JSFiddle to demonstrate the object literal.

Here is the JavaScript for my object literal which I call oPerson.

var oPerson = {
    firstName: "John",
    lastName: "Doe",
    age: Math.floor((Math.random() * 33) + 17),
    "favorite color": "Blue",
    Interests: {
        movies: ["The Blob", "History of the World Part 1", "Ferris Bueller's Day Off"],
        bands: ["Lacuna Coil", "Soft Cell", "Naked Eyes"]
    },
    greeting: function () {
        return "Hello, my name is " + this.firstName + " " + this.lastName + ".";
    }
};

Read the rest of this entry