Shorthand for default values in Actionscript
Posted by Ben Jackson Sun, 04 Sep 2005 20:46:00 GMT
Just discovered this little nugget of wisdom... my usual way of assigning default values for optional function arguments:
arg1 = (null == arg1) ? arg1 : "default";
Can be reduced to:
arg1 = arg1 || "default";
Not a huge difference, but I do this so often that just not having to type "arg1" twice is a huge time saver, especially for variables like "myInsanelyLongFunctionParameter".
Update: Beware of using this trick with any parameter which might come up with a value of 0 or false, as any such values will evaluate the same as if the parameter were null.
