JS Fundamentals - this with functions

by smichelotti

JavaScript

var Person = function(){
    var self = this;
    this.firstName = "Steve";
    this.lastName = "Michelotti";
    this.addresses = [];

    this.sayHello = function(){
        console.log("Hello, my name is: " + this.firstName + " " + this.lastName);
    }

    this.move = function(newAddress){
        console.log(this.firstName + " is moving to: " + newAddress);

        function addAddress(newAddress) {
            self.addresses.push(newAddress);
        }
        addAddress(newAddress);
    };
};

var person = new Person();
person.move("1600 PA Ave");
console.log(person);