问题
After searching many hours i dont find a solution for my problem:
function pseudoclass(Value){
this.Value = Value;
}
aPlayGround = new Array();
aPlayGround[0] = new pseudoclass(0);
var Actual = 0;
var Width = 1;
var bBool = new Boolean(Actual%Width); //left becomes 0%1 ----> false
if (bBool && (aPlayGround[Actual-1].Value < 9)) {}
if i let my browser execute this codeblock i get this error message via mozilla firebug:
"TypeError: aPlayGround[(Actual - 1)] is undefined"
bBool
is my error handler to make sure that the second condition in line 11 doesn't get checked but he still does
it works if i change last line to:
if (false && (aPlayGround[Actual-1].Value < 9)) {}
im actually working on a very ugly workaround that just increases the amount of elements to just bypass the error but there must be some way more elegant way to make the browser ignoring this undefined-error unfortunately im a very beginner in js so please keep it simple thx
回答1:
Don't use new Boolean
, simply cast the result to a boolean using this:
var bBool = !!(Actual%Width);
来源:https://stackoverflow.com/questions/17590180/javascript-override-undefined