1 person found this helpful
how can the 'this' keyword be left off
The binding relates to the label, which is an MXML declaration. The declaration is translated into a class instance representing the label. The label class is extended to incorporate the functionality in your MXML markup.
Using "this" is optional in class code. If you omit "this" then the compiler looks for a variable that matches the variable name - most often a class attribute, so adding "this" would also make the variable name match the class attribute.
When you have a function (class method) there is a possibility of ambiguity where the variable name could refer to a paramter or a local variable belonging to the function. If the variable name refered to was a parameter or local function, then that would be used rather than the class attribute. By explicitly using "this" you refer to the class instance itself, not a local variable or function parameter, so there is no ambiguity. Sometimes it makes no differrence, other times it can be essential where local variables would otherwise be referred to.
In your example, leaving off "this" is fine because there are no competing variables in the same class namespace.
Many people include the "this" reference as a matter of style and to ensure there is no amiguity about their intention. It also makes unintentional references less likely.
The basic message is that MXML components are really class instances and the use of "this" is refering to the properties of that class. The use of "this" in classes is not mandatory, so neither is it mandatory in binding expressions
I'm not sure if that is clear or not!.
The keywork this is not exclusivity of binding expressions.
You use it just to access the current scope and yes, you can suppress it.
Get more information about binding here:
Thanks Pauland, most of that makes sense / is helpful. Can you expand a bit on the first sentences, i.e.:
"The binding relates to the label, which is an MXML declaration. The declaration is translated into a class instance representing the label. The label class is extended to incorporate the functionality in your MXML markup."
Please note my primary language background is Java / C++ if that helps.
Thanks Pablo, I looked through that reference. I didn't find it complete though in describing binding expression syntax (e.g. leaving off the id and have the properties come from 'this'). A binding expression is more than just regular AS syntax, or ?
Thanks Pablo. I was only searching Flex 4, so the link you gave is excellent. Thanks again.
Hey, great. Nice to help you!