Archive for March, 2009

TextMate Jump to Function

My personal battle between TextMate and Eclipse continues. In this case, I wanted to to see if it was possible to recreate the “jump to definition” functionality of Eclipse within TM…you know, when you control click a function name in eclipse will take you to that definition. Well, I found this post which pretty much re-creates this functionality, except using a key commmand instead of control-click, which is fine by me. I just need to add ‘as’ and ‘mxml’ to the list of file names to search through and it worked great. Currently it doesn’t work for getters/setters, I’ll see if I can hook that up as well.

Next up I’d like to see about jumping back and forth between edit locations in files (the option-apple-arrow key combos in eclipse on mac).

Burned by hoisting

A while back I read a post about variable hoisting in Actionscript , and remember thinking how it was weird how that was the first time I'd ever heard about that, and how I'd probably never need to know that if I hadn't until that point anyway. So today I get burned by it. When you declare a variable anywhere within a function, Actionscript 'hoists' that declaration to the top of the function. To quote the original article:

Any variable defined within a function scope, in any structure, at any location, is automatically moved at compile-time to the top of the scope. And it’s accessible anywhere in any of those scopes. In most languages, this would be a compile error.

This is what got me today. In this sample, mainUI and someArray are other properties of the object, but vo is not:

Actionscript:
  1. override public function execute():void {
  2.     var container:Canvas = mainUI.getContainer(vo.dataProvider);
  3.     var dp:ArrayCollection = container.dataProvider;
  4.  
  5.     for each(var vo:ItemVO in someArray){
  6.         doStuff(vo);
  7.    
  8.     }
  9. }

As you can see, in the first line of code I try to call vo.dataProvider, but it should not be defined yet. However, since I declare the var 'vo' in the for each loop, the compiler lifted the declaration to the top of the function, which means that as far as the compiler cares, the vo variable existed before my first line of code.