+ 1
Javascript methods
function person(name, age) { this.name= name; this.age = age; this.yearOfBirth = bornYear; } function bornYear() { return 2016 - this.age; } in the above code we have this.yearOfBirth but i dont see it being defined beforehand or did i get it all wrong ??
1 Resposta
0
'bornYear' is a function, so it should be with parentheses:
this.yearOfBirth = bornYear();
When the above statement is executed, it calls the function 'bornYear()', which returns the needed value to the caller, so 'yearOfBirth' is assigned to that value.