0

JavaScript Objects

please who can shed more light on this? it's quite confusing

25th Dec 2017, 10:43 PM
Marcosx
4 ответов
+ 3
What exactly is it that you find confusing?
25th Dec 2017, 10:46 PM
blackcat1111
blackcat1111 - avatar
+ 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
25th Dec 2017, 10:48 PM
Marcosx
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.
26th Dec 2017, 1:12 AM
Andreas K
Andreas K - avatar
0
Thanks
26th Dec 2017, 5:16 PM
Marcosx