+ 1
What is the point of this.name=name?
I don't understand the reason for the three parts (this, name, name). What is the difference between the 2 name parts? Thank you!
1 Answer
0
I am largely unfamiliar with JavaScript, but that looks similar to Python Object-Oriented Programming. AFAIK, you wouldnāt say āthisā twice in a method definition, I think that was a mistake judging by the title. If that is a method definition like I think, then the reason to assign the value from ānameā to āthis.nameā is that now the value of ānameā isnāt just in the method scope, itās in the object scope. āthis.nameā means āthe name attribute of this objectā. Any other method of the object can now reference āthis.nameā at any time without ānameā needing to be passed as an argument again.
Hope this helps!