Thursday, December 21st, 2006

JavaScript Variable Dump in Coldfusion

Category: ColdFusion, JavaScript, Library

We don’t mention Coldfusion enough. Sorry guys. Rey Bango told us about a JavaScript version of cfdump:

The Dump method is based on one of the tags available in Coldfusion ( <cfdump>) providing the ability to display simple and complex variables in a user friendly way that is perfect for debugging/inspecting data. There is no way to do this with javascript and often I had wanted a method to do this. This method will do just that allowing for an infinite amount of data nesting complete with color coding for different data types, the ability to show/hide the data’s type (String/Number/Boolean/Object/Array/Function), expandable and collapsible tables/keys and cross browser support.

Download the dump function

JavaScript Variable Dump in Coldfusion

Posted by Dion Almaer at 7:51 am

4 rating from 51 votes


Comments feed TrackBack URI

Thanks for the mention Dion! The really cool thing about this is that ColdFusion is not required to make it work. PHP, .Net and Rails developers should be able to benefit from it as well.

Comment by Rey Bango — December 21, 2006

Hmm, I am still fine with firebug’s console.dir(object) – tells me anything i need and i don’t have to include any additional javascript. but great work anyway – gotta test this when i am back @ home.

Comment by .mario — December 21, 2006

Yay, Coldfusion influence in effect on JS! Good to see. I’ll get use out of this. Many thanks for the info!

Comment by Mark Holton — December 21, 2006

Nice work, but it seems broken (at least in Firefox 2), it breaks when trying to call the toString/regex line for determining if an object is a function (fails on both Object and Array). If you need something to determine the type of an object, use the typeof and instanceof operators. On a related note, every serious developer should already be using Firebug which has this functionality baked in – console.log([, , …]).

ColdFusion is still around? If you can write JavaScript, I suggest that its time that you take off the training wheels and upgrade to an actual language. ;)

Comment by Andy Kant — December 21, 2006

@Andy: LOL! That last line was very funny. I hear that often. Honestly though, I’m not sure when you last looked at CF but its progressed substantially over the years and is on par with any development language out there. CFMX supports OO, Java, SMS, and a host of other features. CFMX 8 (AKA Scorpio), will definitely bring a host of new features and performance improvements. CF is definitely not your dad’s CF. ;o)

Comment by Rey Bango — December 21, 2006

I’ll second Rey’s comment. CF is a good language, with its pros/cons like any other. Some people make fun of it because of its tag-based approach, but that’s just silly. I’ve done work with Javascript, Java, C#, PHP, RoR, and CF has its place in the middle of those. For one, PHP could use a cf_dump tag (and some people have ported it).

Comment by Thomas Messier — December 21, 2006

That was a good one ;) ColdFusion is just as advanced as any other language used for building web sites and web based apps, don’t let the tag syntax fool you… and the irony of Andy’s statement is that you can use ECMAscript compatible cfscript blocks in CFML, LOL… Look beyond the simple examples that you’ve seen and start reading up on frameworks like Mach II, Model-Glue, Coldspring, Reactor, Transfer. Look at the Flex 2 integration. Look at what’s coming with Scorpio (CF8). Look at what’s coming with Apollo…

I don’t know why the misconception about CF exists, but it certainly is common… I always thought it was because of the cost of buying a license to use it in production (because that’s what I used to think). Maybe it’s simpler than that. Maybe developers see the tags and think it’s a tiny little tag based scripting language and think that they’re “above” it (in the same way that some think HTML is “easy”, yet their markup looks like crap). That’s a silly mistake to make. CF can be as simple or as complex as you want it to be, and the frameworks and technologies I listed above show it.

Anyway, back on topic… This piece of JavaScript is really well done, and CF developers will definitely feel at home using it to debug their JS (in addition to using FireBug). Just run “dump(myObject)” from the console and up pops the dump window. In the last few days this function has come in very handy for me while writing jQuery plugins. I love it :)

Comment by Justin Carter — December 21, 2006

@Justin: Sweet another fellow CF/jQuery developer!

Comment by Rey Bango — December 22, 2006

Ahh.. So funny to see people still bashing ColdFusion.. Gosh, after over 10 years, you’d think people would take the time to educate themselves. If ColdFusion is not a real language, how does it manage to power the #1 web site on the net and why is it used by 75 of the Fortune 100 companies and over 10,000 companies worldwide?

Comment by Joe Danziger — December 22, 2006

@Rey etc, I third the motion… ColdFusion is easy to learn and for some reason “serious” programmers who don’t use CF seem to equate that with “limited”. The fact of the matter is that CF has a very gradual learning curve, and I wish some of the other “serious” languages had taken their cues from ColdFusion, instead of leaving me to drown unless I figured it all out at once.

Comment by Mike Ritchie — December 22, 2006

Some developers seem to have elitist attitudes, thinking that because something is harder (ie. all command-line, no GUI) it’s better. I think that’s a pity, and they’re the only ones to lose by limiting themselves. CF is easy, especially as far as getting started, it’s ridiculously easy. I mean, nothing beats CFQUERY…

Comment by Thomas Messier — December 22, 2006

…the object-oriented features in CFMX (since Coldfusion 6 and 7) are very powerful (“extends” for inheritance, the THIS scope in CFC’s for instantiating objects, etc). Not to mention the ability to turn any function into a SOAP web service pretty easily! Check them out!

Comment by Mark Holton — December 27, 2006

nifty stuff :)

thanks a bunch

Comment by tmpvar — January 25, 2007

Awesome thats all I can say very nice.

And who cares if it models CF Its a great addition to a development toolset.

Comment by Nathanael waite — August 23, 2007

Just a heads up to anyone reading this that the dump function has been updated to have a jQuery plugin also.

Comment by Ian Sheridan — October 12, 2007

Leave a comment

You must be logged in to post a comment.