On 4/17/13 6:13 AM, "Erik de Bruin" <e...@ixsoftware.nl> wrote:
> Ok,
>
> I'm currently wrestling the 'JSFlexJSEmitter::emitIdentifier()' beast,
> in order to get the self/this references under control.
>
> I'm aiming to completely get rid of 'var self = this;' and use 'this'
> when required by JS and 'goog.bind' when a self reference was needed
> as an argument for a function call...
OK, good luck with that. In theory I have added enough tests to catch any
issues with your changes (once you replace 'self' with 'this' in the tests).
There are currently a lot of 'if' cases in emitIdentifier. I keep thinking
it can be much simpler, that:
1) if you get an identifer not in a MemberAccessExpression, you check if it
is local or a param, then if it is a member and only then add 'this'
2) if you are in a MemberAccessExpression, you have to walk up the tree of
MemberAccessExpressions to determine if you are the leftmost identifier.
That's the only other situation where you need to add 'this', or if a
static, add the full path.
3) you check if you are the rightmost node in a tree of
MemberAccessExpressions and if it is an assignment, and only then use the
setter pattern
4) you check if you are a function as a parameter and add goog.bind.
But I could be wrong about that. I did add code for #2 and #3 in parts of
emitIdentifier, but I didn't put it everywhere because I was also thinking
of refactoring emitIdentifer, but I'm more than happy to let you take it on.
--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui