+ 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?
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.
+ 5
I think you need to modify the question title to a better one.