0
JavaScript Objects
please who can shed more light on this? it's quite confusing
4 odpowiedzi
+ 3
What exactly is it that you find confusing?
+ 1
function person(name, age) {
this.name= name;
this.age = age;
this.yearOfBirth = bornYear;
}
function bornYear() {
return 2016 - this.age;
}
var p = new person("A", 22);
document.write(p.yearOfBirth());
why is parenthesis added to p.yearOfBirth
0
Actually "yearofbirth" contains a function called "bornyear". If you call a function you have to add parenthesis for transmitting data to the function's body. In this case it is empty because "bornyear" does not have any parameters.
Hopefully, this explanation is not too confusing.
0
Thanks