Skip to content

Instantly share code, notes, and snippets.

@nola
Forked from keeganbrown/A-Pen-by-Keegan-Brown.markdown
Last active January 3, 2016 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nola/8422081 to your computer and use it in GitHub Desktop.
Save nola/8422081 to your computer and use it in GitHub Desktop.
<div id="output"></div>
//create an object
var friends = {};
var Friend = function ( config ) {
this.firstName = config.firstName;
this.lastName = config.lastName;
this.number = config.number;
this.address = config.address;
this.email = config.email;
this.getMyFullName = function () {
logger( this.firstName + " " + this.lastName );
};
this.getMyFullName();
}
//add people to it
friends.bill = new Friend({ //observe this declaration as bill is an object of friends
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
});
//add another
friends.steve = new Friend({
firstName: "Steve",
lastName: "Jobs",
number: "(408) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']
});
//log out all contents of the object
function list (obj) {
for(var prop in obj) {
logger(prop);
}
};
//search for "steve"
function search (name) {
for(var prop in friends) {
if(friends[prop].firstName === name) {
logger(friends[prop]);
return friends[prop];
}
}
};
function add (firstName, lastName, phoneNumber, email){
friends[ firstName.toLowerCase() ] = new Friend({
firstName: firstName,
lastName: lastName,
number: phoneNumber,
email: email
});
}
function logger () {
for ( var i in arguments ) {
document.getElementById("output").innerHTML += "<br>"+ arguments[i];
console.log(arguments[i]);
}
}
add("Cyril", "Celestine", "5042282838", "cc@cc.com");
list(friends);
var tmp = search("Cyril");
console.log(friends);
tmp.getMyFullName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment