function - JavaScript calls to methods from within constructors -


i reading re-introduction javascript on mdn website , came across in custom objects section:

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; } 

it says on mdn website can make reference personfullname() , personfullnamereversed() functions within person constructor typing in names , assigning them values 2 variables stated in code above (this.fullname , this.fullnamereversed). clear me, question why brackets next personfullname , personfullnamereversed omitted? shouldn't say:

this.fullname = personfullname(); this.fullnamereversed = personfullnamereversed();? 

the way presented in example mdn website feel fullname , fullnamereversed properties person constructor pointing declared global variables instead of functions declared outside of person constructor.

if add brackets, you'll call functions , assign return values this.fullname , this.fullnamereversed.

the code referring to functions, not calling them.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -