Note that there actually is no such thing as type casting in JScript. It may look and work like type casting, but actually you're calling a function which happens to behave like a cast.
The following code:
Javascript code:
var bool = (Boolean)(5);
is identical to:
Javascript code:
var bool = Boolean(5);
The Boolean() function acts like a cast, in the sense that it takes any variable and produces a boolean. When working with inheritance, the difference is much more clear.
Javascript code:
var A = function(){};
var B = function(){};
B.prototype = new A;
var b = new B;
Debug.Trace(b instanceof A); // -> true
Debug.Trace(b instanceof B); // -> true
var a = (A)(b);
Debug.Trace(a instanceof A); // -> false?!?!
Debug.Trace(a instanceof B); // -> false?!?!
When B inherits from A, one could try to cast an object b of class B to class A using something like (A)(b). However, this simply calls the function (constructor) A with the (unused) parameter b and thus this call returns void. Because JScript uses prototypical inheritance, such casting is simply not possible. Even with primitive types such as Number or Boolean, you'll always end up with a copy of the original. You probably won't even notice this since those primitive types don't compare by reference, but it happens.
Another suggestion: don't use "new Boolean(o)" when converting to a boolean, either use "Boolean(o)" or "!!o". Here's why:
Javascript code:
var a = Boolean( "true" );
Debug.Trace(a); // -> true
Debug.Trace(typeof a); // -> boolean
var b = !!"true";
Debug.Trace(b); // -> true
Debug.Trace(typeof b); // -> boolean
var c = new Boolean( "true" );
Debug.Trace(c); // -> true
Debug.Trace(typeof c); // -> object?!?!
The explanation for this is that when using "new", you're always creating an object. The same happens with the "this" object, it's always an object - even when you're working on a primitive class!
Javascript code:
Number.prototype.isFive = function() {
Debug.Trace(typeof this); // -> object?!?!
return this === 5;
}
Debug.Trace( (5).isFive() ); // -> false?!?!
So yes, either compare the string to '0000' or use a conversion such as:
Javascript code:
bTabsEnabled = (Boolean)((Number)(reg.toArray().join('')));
or simply:
Javascript code:
bTabsEnabled = !!(1*(reg.toArray().join('')));
At least it'll have the proper type.