Wednesday, August 5, 2009

Optional Parameters in cfscript functions

Ever get the The parameter [parameter] to function [function] is required but was not passed in?
Here's how to get around that:

function [function name]([param1]) {
       var [param2] = [default value];
       if (arraylen(arguments) gt 1)
              [param2] = arguments[2];


  1. There's a song by the Aquabats called "nerd alert". It's quite funny and you should give it a listen.

    Anyways, I was on jacob da jew's blog and found this:

    "Am I the only one who doesn't care about donuts, pizza, etc? Keep your donuts and bring me meat and beer!"

    I just wanted to let you know that it sent me into guffaws.

  2. Listened to the think it's funny?!
    You want funny, White and Nerdy

    So why didn't you comment there then. :-P

  3. Forgot to mention - I hate ColdFusion for lack of obvious functionality and need to re-implement it all by yourself!

  4. Like what? CF8 introduced use of regular operators for comparison and ++ in cfscript. CF9 supposedly allows total scripting.

  5. Um, like this post? No optional arguments in cfscript? Remember? Implementing it 10 years after everyone else doesn't take away years of annoyance for those of us forced to use CF.

  6. I've been using CF for close to 10 years and I like it. And with tags and functions added in CF8 and CF9 and the performance monitor in CF8, I like it even more.