+ 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 RĂ©ponse
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!