Forum Discussion
GandK-Geoff
15 years agoVisitor
"jbrave" wrote:
One thing I see in your code and in TheEndless code is these constructions where it appears you are embedding a function call in an roAssociativeArray and giving them a label and then calling them as a method. I don't completely understand this- it seems like It adds an extra level of unreadability to the code but maybe allows you to simplify your code at the same time? Does this stuff execute faster or something?
He is not putting a function *call* in the roAssociativeArray ("AA" for short), he is putting a function *reference* into the AA. That is, in fact, the way that objects are created in BrightScript; a user-defined object is just an AA with some entries that are member variables and some entries that are methods (function references). ("Native" objects created with CreateObject() are actually C++ objects.)
BrightScript AA-based objects don't really have classes and inheritance in the classic OO style; they are in this sense somewhat weaker even than JavaScript's object system. Still, they support encapsulation, polymorphism, and namespace control (methods can be defined with inline anonymous function definitions, thus avoiding pollution of the top-level namespace). That's good enough to get a lot of useful work done.