+ 1

What a hell?

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()); Enybody explain please I’m understand it right? Document.write-> p -> function person -> this.year of Birth -> function Born Year -> function person ( this.age) ? It is right order output result?

1st Feb 2020, 9:24 PM
Шабалин Евгений Дергеевич
2 Answers
+ 4
Do you mean you want to know in which order the code is executed? First, the object p will be made, that's the function 'person'. Then, when you document.write using the method call YearOfBirth, we go into your person p, find a pointer to the function bornYear, and from there, p's attribute age is accessed. The calculation result is returned to the point of document.write, and the output is done.
1st Feb 2020, 9:52 PM
HonFu
HonFu - avatar
+ 5
I think you need to modify the question title to a better one.
1st Feb 2020, 10:31 PM
Sonic
Sonic - avatar