I don’t know if “curly braces are ugly” would be enough of a reason for me,
personally, to abuse the language like this :). I’d probably just play with
whitespace:

if (cond){ callback(); return; }

But I think the cleanest brace-free option would certainly be the comma
operator:

if (cond)
    return callback(), undefined;

Parentheses might make it clearer:

if (cond)
    return (callback(), undefined);


On Wed, Jun 8, 2011 at 7:30 PM, Anton Kovalyov <[email protected]> wrote:

>  I used the void operator today in a case when I needed to call a
> function, discard its return value and then return undefined. I did that
> mostly to be able to omit curly braces in the one-line if statement (i
> personally think they are ugly, especially when used in a very small
> constructions; python thing):
>
> function sample(callback) {
>   // Do something
>
>   if (cond)
>     return void callback();
>
>   // Do something else
> }
>
> Now I am curious in other cases when void is useful (except for
> bookmarklets, of course). Do you know any?
>
> Anton
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to