AllThingsNetwork.org Logo

Security Simplified



Object Creation Functions, Inheritance, Properties, Methods, Instantiation

Example #1

This example shows the creation of the contact object type and it's instantiation.

Contact Input






Contact List

FOREACH Loop Code Snippet

function Contact(name, phone, address, email) {
    this.name = name;
    this.phone = phone;
    this.address = address;
    this.email = email;
}

function addContact() {
    var nameElement = document.getElementById('name');
    var phoneElement = document.getElementById('phone');
    var addressElement = document.getElementById('address');
    var emailElement = document.getElementById('email');
    var name = nameElement.value;
    var phone = phoneElement.value;
    var address = addressElement.value;
    var email = emailElement.value;
    var newContact = new Contact(name, phone, address, email);
    var contactList = JSON.parse(localStorage.getItem("contactList"));
    if(contactList === null) {
        contactList = Array();
    }
    contactList.push(newContact);
    localStorage.setItem("contactList", JSON.stringify(contactList));
    nameElement.value = "";
    phoneElement.value = "";
    addressElement.value = "";
    emailElement.value = "";
    updateTable();
}