the singularity of being and nothingness
ColdFusion 9 and Ternary Operation
Just a quickie
I learned about ternary operators in JavaScript probably about 6 months ago, and absolutely fell in love with it. After all, who doesn’t love to convert something bulky to something clean and able to fit on one line?
THEN:
var myidea = ''; if(thething=='yes) { myidea = 'great'; } else { myidea = 'lame'; }
NOW:
var myidea = thething=='yes' ? 'great' : 'lame';
The other day, I was busting out some <cfscript>, and came across a bit of evaluation where a ternary operator would be PERFECT. Having no idea whether or not it would work, I gave it a shot and voila!, it’s magic!
<cfscript> myidea = thething=='yes' ? 'great' : 'lame'; </cfscript>
Now after a bit more investigating, turns out this is in the “only works for CF9” domain. Nonetheless, pretty nice–I love saving keystrokes!
Print article | This entry was posted by existdissolve on June 23, 2010 at 9:45 pm, and is filed under ColdFusion. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |