[thelist] RE: JS Boolean Object...

jsWalter jsWalter at torres.ws
Thu Dec 4 15:18:11 CST 2003


> -----Original Message-----
> From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
> Sent: Thursday, December 04, 2003 2:57 PM
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] RE: JS Boolean Object... part 2

> >    if ( bolValue  == 'true' )  // not what I'm looking to do
> >       // do something here
> >    else
> >      alert ( bolValue.err );
>
> > I'd rather not do this.
>
> Why not?

because I'm just being difficult.

because if ( bolvalue ) { } is how booleans work. (bolValue =='true') works,
but is not neccessary with a boolean variable.

And I'd like to use this variable type as it is designed, but then add
something to it to make a bit easier.


> I'm a bit confused on what you are trying to do, can you
> provide some more context? What is it you really are testing..
> someVar? What does your someFunc() do?

someFunc() does a test an whatever (it is unimportant here) and returns a
boolean indicating success or failure.

What I'd like to have is the reason for failure attached to this boolean
variable. So if it comes back FALSE it will also tell me why it failed.

Right now, I'm having by validation methods call a secondary method to
"publish" the failure reason and then return the boolean. I'd like to have
these validation methods do what they are supposed to do, validate, return
pass/fail and tell me why it failed, not call another method to tell me why
it failed.

encapsulation, you know. There is no reason that these validation methods
need to know about any other methods in order to do its job.

Like I said, I'm being picky.

another list answered, and gave me this...

  objX = test2 ( 6 )

  if ( objX )
    document.write( 'OK' );
  else
    document.write( 'Too bad:' + ' - ' + objX.err );

  function test ( x )
  {
    // default values
    var bolTest = new Boolean ( true );
    Boolean.prototype.err = "";

    if ( x != 6 )
    {
      Boolean.prototype.err = "I asked for a 6! not " + x;
      bolTest = false;
    }

    return bolTest;
}

It works just fine.

Does what I need.

But it never accured to me to prototype the Boolena itseslf.

Too bad I can't directly assign a string to the err property. But, hey, I
can't be too pick! ;)

Walter




More information about the thelist mailing list