Week 7 Lesson 2

Object Literals Constructor Functions

by Lucille Kenney

JavaScript

/* Object Literals look like this: */

/*
var myObject = {
	property1 : "value1",
	property2 : 2,
	function1 : function(){
		//do something here
},
}
*/
var myAddrBookEntry = {
    fname: "Larry",
    lname: "Bouthillier",
    addr: "Rhode Island",
    email: "[email protected]"
}

/* Constructor Function looks like this */
/*
function myObject() {
    
}
*/

function AddrBookEntry(f, l, a, e) {
    this.fname = f;
    this.lname = l;
    this.addr = a;
    this.email = e;
    
    this.getFullName = function(){
                return this.fname + " " + this.lname;
    }
}

/* So now I've defined an object and this is how I use it */