Constructor Function

by Susan Delgado

JavaScript

var Person = function (firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
};
Person.prototype.getFullName = function () {
    return this.firstName + " " + this.lastName;
};
Person.prototype.greet = function (person) {
    if (person instanceof Person) {
        return "hello " + person.getFullName();
    } else {
        return "Hey, There!";
    }
};
var person = new Person("jane", "Doe"),
    person2 = new Person("John", "Doe");

alert(person.greet(person2));