PDA

View Full Version : Simple Explaination Pls


sloppydog
07-02-2009, 08:28 PM
if I were to write a function/method like this:


public function myFunction(x:Number)
{
this.x = (x == undefined)?0:x;
}


what does this do:
?0:x


I am looking at various code bits from better programmers than I and came across this. My guess is that if x is undefined set this.x equal to 0 otherwise set it to x. But I am not 100 percent sure.

Thank you in advance for your help.

Heloed
07-02-2009, 09:22 PM
Yep, you've got it.

But it's really just a lot easier to do:

public function myFunction(x:Number = 0) {
this.x = x;
}

Which sets the default as 0 and so you don't have to worry about checking if it's defined or not, it's 0 unless something gets passed in