For those of you uber coders, this may seem trite, and “duh”. To me, though, I’m still learning, so I thought it was kind of a neat step in my education.
I found a use for putting properties on prototypes Sunday. I was coding about 6 classes who each had similiar properties, but a few had 2 or 3 that were different as well as all having about the same defaults. A lot of these properties won’t really get set either, therefore, not causing the instance of the class to get it’s own copy.
So, I put them all on prototype because:
– all 6 classes have them
– most classes only modify half of the properties to be different from the defaults
– majority of instances will only read the properties, not set them resulting in very few local instance copies
Ever since I learned that prototpye properties get transferred to local copies upon a setting of that property, I was distraught at how to implement constants. I then found if I just put my functions on prototype, but all of my properties in the constructor, things worked great. Glad to know I can still save some memory this way!