3 year-old prototype bit me

I was having problems with the mx.formatters.CurrencyFormatter in Flex. It takes a number or string, and formats it to look like currency. For example, 1.2567878 can be made to look like $1.25. For some reason, it was not working in my DataGrid and I had no idea why. I built some test cases, files that have nothing but a TextInput and a formatter, and they worked so I was really having a challenge figuring out why. Then, it worked when I ran the app in debug mode in Flex Builder 1.5, but didn’t work in normal mode.

Three hours later, it turns out some code written in 2003 for our debugger was overwriting String.prototype.toString. Since the mx.formatters.NumberBase, does a:

return value.toString()

The modified toString function was munging the results. No debug code in your app, no problem.

Anyway, I really like protoypes. They allow a lot of meta-programming concepts to be done, and really help those creating languages to have the developers build the future API for you based on what they overwrite, just like we did with Flash 5 & 6 in ActionScript 1. I think there is still a lot of room for growth for tools to take advantage of prototype features at compile time, and build upon some of those runtime goodies.