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!
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!