block by joyrexus eb7ed0a5551d071702d0

Prototype vs object style

Prototype style

function Person(first, last) {
    this.first = first;
    this.last = last;
}

Person.prototype.greet = function () {

    console.log('Hello', this.first, this.last + '!');
};

var bob = new Person('Bob', 'Jones');
bob.greet(); // Hello Bob Jones!

Object style

function person(first, last) {

    return {
        first: first,
        last:  last,
        greet: function () {
            console.log('Hello', first, last + '!');
        }
    };
}

var bob = person('Bob', 'Jones');
bob.greet(); // Hello Bob Jones!

Reference

index.js