DEV Community

Discussion on: Back to Basics: Understanding and Conquering "this" in Javascript

Collapse
 
dhorse1 profile image
David G. Horsman

Thanks, I wasn't sure about 'this' in a closure but you confirmed my assumptions.
"This" can be a pain in c#. It's a read only value you can't pass by reference. I create a Self field during construction and pass that instead but you can't do that in constructor " x() : baseX() " calls.

Collapse
 
tilkinsc profile image
Cody Tilkins

Try singletons instead.

SomeClass.Instance.SomeFunc()

Using 'This' should only boil down to extra specification on which fields you are modifying. You shouldn't have to use it outside the class and its available everywhere in the class. If you need multiple instances elsewhere, it's much better to consume an array of the data and pass around a reference to that.