Forked from keeganbrown/A-Pen-by-Keegan-Brown.markdown
Last active
January 3, 2016 06:19
Revisions
-
nola revised this gist
Feb 10, 2014 . 2 changed files with 1 addition and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,9 @@ var Friend = function ( config ) { this.number = config.number; this.address = config.address; this.email = config.email; this.getMyFullName = function () { logger( this.firstName + " " + this.lastName ); }; this.getMyFullName(); } -
keeganbrown created this gist
Jan 14, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ A Pen by Keegan Brown --------------------- A [Pen](http://codepen.io/keeganbrown/pen/lCnBf) by [Keegan Brown](http://codepen.io/keeganbrown) on [CodePen](http://codepen.io/). [License](http://codepen.io/keeganbrown/pen/lCnBf/license). This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <div id="output"></div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ //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", "[email protected]"); list(friends); var tmp = search("Cyril"); console.log(friends); tmp.getMyFullName();