> I am curious to refreshing my mind if the JS intepreter short
> circuits & bit masking. In other words:
>
> fn(a) & fn(b)
>
> I have to check that out. I guess it depends on the compiler or
> intepreter.
>
I didn't roll up my sleeves and test this with JS, but I did some
googling to see. Quick reading indicates bitwise operators are not
short circuiting operators. I normally don't think of them as such
when programming and depending on the word size of the computer and
the language you are using, it would be think of it being unreliable
to be used in this way.
For example, paul had:
condition == true ?
foo()| //Execute foo
bar()| //Execute bar
something() //Execute something
:0;
Did he really want == above?
Anyway, you can get two different conditions depending on what bitmask
and that the function foo(() and bar() returns
var s = "";
function foo() { s += "foo:"; return 2;}
function bar() { s += "bar:"; return 1;}
function something() { s += "something:"; return 1;}
condition = true ?
foo()& //Execute foo
bar()& //Execute bar
something() //Execute something
:0;
console.log("funcs called: : "+s);
console.log("condition: "+condition);
console.log("-----------------------------");
Do the same for using | operator. With & you get zero (0), with |
you get three (3).
But there is no short circuiting which is shown by printing out the s
string.
I guess I can see some clever usage of this, like calling all the
functions and making using state flags to determine what happen in
each function.
Anyway... <g>
--
HLS