Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Notes</title>
- </head>
- <body>
- <h3 id="headline">JavaScript!</h3>
- <script type="text/javascript">
- function begetObject(o) {
- function F() {}
- F.prototype = o;
- return new F();
- }
- jsc = {};
- jsc.contactList = [];
- jsc.protoContact = {
- first : "DEFAULT FIRST NAME",
- last : "DEFAULT LAST NAME",
- email : "DEFAULT EMAIL",
- display : function() {
- console.log(this.first + " " + this.last + " " + this.email);
- }
- };
- jsc.objExtend = function(target, newProps) {
- for (var key in newProps)
- target[key] = newProps[key];
- };
- jsc.buildContact = function (first, last, email) {
- var contact = begetObject(jsc.protoContact);
- jsc.objExtend(contact, {
- first: first, last: last, email: email
- });
- jsc.contactList.push(contact);
- }
- jsc.findContact = function (last) {
- for (var i=0; i<jsc.contactList.length; i++)
- if (jsc.contactList[i].last == last)
- return jsc.contactList[i];
- }
- jsc.editContact = function (contact) {
- var newEmail = prompt("Enter new email for " + contact.first + " " + contact.last);
- if (newEmail) {
- contact.email = newEmail;
- }
- }
- jsc.removeContact = function (contact) {
- var i = contactList.indexOf(contact);
- contactList.splice(i, 1);
- }
- jsc.test = function() {
- jsc.buildContact("Adam", "Breindel", "adbreind@gmail.com");
- jsc.buildContact("Fiid", "Williams", "fiid@gmail.com");
- jsc.buildContact("Eric", "Pearson", "eric@gmail.com");
- var last = prompt("last name");
- var contact = jsc.findContact(last);
- jsc.editContact(contact);
- contact.display();
- }
- jsc.test();
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment