Don't add object.prototype's in actions

During some recent development, I figured I would flex FW’s environment to better suit my needs by adding some Object methods that I thought would be useful to me, like String.unQuote(). I also figured that the JS environment was discrete to each Action; after all, a crash in one Action does not hinder other Actions from publishing.

Upon testing, and just by coincidence as I usually test with just the single Action so as to only see its output, I had another Action applied to the page. During publish I had an alert message pop up that caused me some consternation trying to figure out its source. I must have dug through my code two or three times looking for the alert. Come to find out the alert was from that other action; triggered by a ‘for(var i in XXX)’ loop.

The moral: Don’t alter/create ‘prototypes’. FW does a decent job of keeping Actions segregated, but the JS engine is apparently generated once and reused for all Actions on that page. Any alterations made by one Action will be seen (and felt!) by all others.

Fortunately, it was early in development and not much time was invested in utilizing any of these methods yet.

Lesson learned.


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This is precisely why the Prototype guys get very angry when anyone posts code using for … in to do anything besides iterate over the properties of an object.

http://www.prototypejs.org/api/array

I’ve been thinking about making some test Actions that use Prototype-style coding, just to see if it makes any new functions possible. But it’s interesting to discover that I wouldn’t have to just worry about my own code (and I am a big offender in the for … in department) but everyone else’s as well. Perhaps if I namespaced everything into classes there might be some insulation.

Walter


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options