I came across this snippet of code on the MDN(Mozilla Developer Network) tutorial for JavaScript(by the way, a wonderful read). MDN JavaScript Re-introduction
function personFullName() {
return this.first + ' ' + this.last;
}
function personFullNameReversed() {
return this.last + ', ' + this.first;
}
function Person(first, last) {
this.first = first;
this.last = last;
this.fullName = personFullName;
this.fullNameReversed = personFullNameReversed;
}
What intrigued me is the way the functions are called. The typical (); is not used to make the function call in the Person function. Within the Person function, we see that :
this.fullName = personFullName;
is used instead of
this.fullName = personFullName();
Here, the 'personFullName' is used like a variable or a property rather than, what it truly is, a function. Could someone shed a light on why this is so?
alert('foo')in any function and see that it doesn't appear