On Thu, Jun 11, 2009 at 7:51 AM, Joel Webber <j...@google.com> wrote:
> +1 Ray. Now here's the really tricky question. Is there any way we can take > advantage of Javascript's "for (x in y) { ... }" syntax (and should we, > given its spotty performance)? My intuition tells me that the only way we > could use it would be through a callback, because there's nothing like .NET > generators/yield in Javascript. First problem is you have to have some knowledge of the key domain in order to use the keys as raw JS attributes. Ie, basically they need to be integers or strings that don't conflict with particular reserved words like __proto (or you prefix all the keys, like what is done in FastStringMap). I think assuming the keys are safe is ok for specific use cases, but not ok for a general purpose data structure (so I agree with prefixing keys in FastStringMap while avoiding them in CurrencyList for example). Regarding the for(x in y) construct, it seems conceivable the compiler could recognize the code generated by the normal Java->JS compile of for(x : y.elements()) and rewrite it to the native JS code where appropriate as a peephole optimization. -- John A. Tamplin Software Engineer (GWT), Google --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---