+ 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!

16th May 2018, 10:39 PM
Watchtower
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!
13th Apr 2024, 4:28 PM
Wilbur Jaywright
Wilbur Jaywright - avatar