0
about defining method object
why my method object doesn't output? function person3(name, age) { this.name= name; this.age = age; this.yearOfBirth = bornYear; } function bornYear() { return 2016 - this.age; } var p8=new person3("Alex",29); document.write(p8.yearOfBirth); output is: function bornYear() { return (2016 - this.age); }
2 Answers
+ 2
Instead of
p8.yearOfBirth
write
p8.yearOfBirth()
It should work, but I wouldn't define object methods this way
+ 2
Value of yearOfBirth is function, so you should use yearOfBirth as 'yearOfBirth()'.