(foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() :
trace(sorry! no soup for you!);
I feel like I need a shower after that one. ;)
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
Gee ! didn't know it was such a dirty hack ! lol
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks
| BLITZ
Sent: 29 janvier 2007 13:14
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Shorhand for if statement without else statement
Heh, that's nothing. I don't have the code available, but I once
wrote a ?: statement that was something like 16 deep.
Ah, those were the days. :)
-Andy
On 1/29/07, Steven Sacks | BLITZ [EMAIL PROTECTED] wrote:
(foo) ? foo() : (bar) ? bar() : (foobar) ? foobar() :
trace(sorry! no soup
Usually ?: notation is used specifically for quickly choosing between
2 values (picking between 2 things inline). That's a case where you
really have to have an else, otherwise you wouldn't have a value to
represent the failure case of the IF part.
If you're doing logic that isn't inline in a
if ( condition){
}
?
- Original Message -
From: Helmut Granda [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, January 26, 2007 9:01 PM
Subject: [Flashcoders] Shorhand for if statement without else statement
does anybody knows if there
hello :)
I don't understand you question ? why you don't use the if keyword ?
if ( isNaN(x) ) x = 0 ;
you can use the || operator too
function write ( txt )
{
var message = txt || empty message ;
trace(message) ;
}
write(hello) ; // output : hello
write() ; // output : empty message
For that specific example, you can usually turn lines like
return object ? true : null;
into
return Boolean( object );
as long as object != 0 and your code doesn't mind getting a false instead of a
null. Most objects, as long as they exist, evaluate to Boolean true.
Really, though, the
thanks everyone for your comments, yes in reallity I use the regular if
{}else{} statement, but I was wondering if there was something similar to
when you dont need the else statement, sort of testing on the fly
but i think Mark made a good comment on use a return Boolean ( object );
I dont
Hello :)
warning with the Boolean( o ) if your object is a number... the Boolean(0)
is false but :
var n = 0 ;
trace(Boolean(n)) ; // false
When you test a number the isNaN(n) is better i think :)
EKA+ :)
2007/1/26, Helmut Granda [EMAIL PROTECTED]:
thanks everyone for your comments, yes
does anybody knows if there is any short hand for if
statement without the else statement?
1. You can remove the braces.
I always use:
if (true) something();
But rarely use:
if (true) something();
else somethingElse();
because it can get lost visually in code.
2. Inline conditional
I
Hello :)
In FDT for example : cond ? methodA() : methodB() failed :)
The operator cond ? true : false is used to return a value but isn't really
the good solution to launch method i think :)
EKA+ :)
2007/1/26, Steven Sacks | BLITZ [EMAIL PROTECTED]:
does anybody knows if there is any
On 1/26/07, Steven Sacks | BLITZ [EMAIL PROTECTED] wrote:
does anybody knows if there is any short hand for if
statement without the else statement?
1. You can remove the braces.
I always use:
if (true) something();
I like it...
___
-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of eka
Sent: Friday, January 26, 2007 2:27 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Shorhand for if statement without
else statement
Hello :)
In FDT for example : cond ? methodA() : methodB() failed
( condition ) ( code );
Hot! I wonder how many of these shortcuts we can come up with that
nobody would use unless they were trying to show off to other
codemonkeys. :)
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or
Subject: Re: [Flashcoders] Shorhand for if statement without
else statement
Hello :)
In FDT for example : cond ? methodA() : methodB() failed :)
The operator cond ? true : false is used to return a value
but isn't really the good solution to launch method i think :)
EKA
15 matches
Mail list logo