+ 2
Help with functions
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 I can't write : document.write(p.age()); to print the age from the function?
3 Respostas
+ 1
age property is not a function. it's an attribute. So Parenthesis not need there. You can call p.age but yearOfBirth is assigned a function so you need parenthesis () to call it..
+ 1
Got it now, thanks for the explanation
+ 1
You're welcome..