JSON Examples

4- Object Functions (Custom)

Output

JS

var Person = {
        firstName:  'Joe',
        midName:    'Alan',
        lastName:   'Dokes',
        age:        '35',
        getFirstName: function() {
            return this.firstName;
        },
        setFirstName: function(n) {
            this.firstName = n;
        },
        getFullName: function() {
            return this.firstName + ' ' +
                   this.midName + ' ' +
                   this.lastName;
        }
    }

HTML

<script>
    document.getElementById('info').innerHTML = 
                    Person.getFullName();
</script>