I am finally getting around to writing stuff in cfscript, and so I am starting with writing some needed formatting functions. Here is an example:
Function FormatBoolean(MyBool, Format) {
Switch(Format){
Case "YES/NO":{
If (MyBool eq 1)
Return "YES";
Else
Return "NO";
Break;
}
Default:{
If (MyBool eq 1)
Return "Yes";
Else
Return "";
Break;
}
}
}
What I would like to do is make Format an optional argument. If you don’t include the argument, the function will currently still run, but it won’t find format, and it seems that cfparam did not get translated to cfscript.
Will I just have to check if Format is defined and give it a value? Or is there a nicer way of doing this?
Thanks
Personally I prefer to set defaults to this kind of arguments. Also I’ve refactored function a bit… But not tested 🙂
Please note that
(arguments.MyBool EQ 1)may be replaced with(arguments.MyBool), so it covers all boolean values. You may be interested to make it more reliable, something like this(isValid("boolean", arguments.MyBool) AND arguments.MyBool)— this should allow to check any value at all.