[thelist] JS Boolean Object...

jsWalter jsWalter at torres.ws
Thu Dec 4 17:36:05 CST 2003


> -----Original Message-----
> From: Jeff Howden [mailto:jeff at jeffhowden.com]
> Sent: Thursday, December 04, 2003 4:25 PM
> To: jsWalter at torres.ws; thelist at lists.evolt.org
> Subject: RE: [thelist] JS Boolean Object...
>
>
> walter,
>
> ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> > From: jsWalter
> >
> > bolValue = someFunc ( someVar );
> >
> > if ( bolValue )  // true
> >     // do something here
> > else
> >     alert ( bolValue.err );
> >
> >
> > As you can see, I need to define a var as a Boolean and
> > if I have a problem, add a message element to the
> > Object.
> ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
>
> in your case, "if(bolValue)" becomes a check for existence, which will
> return true.

That is not correct, according to my experiments...

    bolValue = someFunc ( 7 );

    if ( bolValue )  // true
        alert ( 'yes' );
    else
        alert ( 'no' );

    function someFunc ( x )
    {
       y = ( x == 6 );   // y is a boolean
       return y
    }


> if it's an object and you're adding a property if there's an
> error, then try this instead:
>
> if(bolValue && !bolValue.err) // true
>   // do something here
> else
>   alert(bolValue.err);

yes, that would work, but it does not follow "standard" boolean logic flow.

I didn't want to make this rocket science, or something special that a
developer had to learn in order to use my class methods.

    if ( bolValue )  // true

this follows "normal" coding practices.

adding the '.err' to the boolean object, yes I admit, is a step beyond
"standard", but I didn't think it was that far "from the tree".

>  if(bolValue && !bolValue.err)

I thought of that, used it even. It just didn't seem like the way to go with
this.

Thanks though.

Walter

PS: Jeff, there is a binary waiting for you.




More information about the thelist mailing list