Tobie Langel wrote:
> Hi all,
>
> I find myself writing code like that the whole time:
>
>     example = example === undefined ? null : example;
>
> We could imagine the following utility function:
>
>     $default = function(value, default) {
>       return value === undefined ? default : value;
>     }
>
> So that the above could be shortened to:
>
>     example = $default(example, null);
>
> We could even decide to shorten it to $d:
>
>     example = $d(example, null);
>
> I'm not 100% sure I like it... so I'm submitting it here for
> discussion before eventually posting a patch.
>
> Regards,
>
> Tobie
>   
I like it it concept, but it does make code generally less readable.  If 
we do decide to move forward, however, may I suggest something from the 
SQL family:

function coalesce() {
  return $A(arguments).find(function(arg) {
    return !(arg===undefined || arg===null);
  }
}

example = coalesce(example, null);

Feel free to change it.

--Ken

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to