javascript - Comparison to -1 or undefined don t work, either with == or === -
here sample of code:
do { line=gets(smil); if (line===-1){console.log("abort");callback(-1);} console.log("line= "+line); }while(line.search("<video")===-1);
the first output goes well, suddenly, get
line= -1 typeerror: object -1 has no method 'search'
gets custom function, wich return either string or -1 in case of error.
i tried == instead of ===, same.
i tried replace return -1 of gets undefined, get
line= undefined typeerror: cannot call method 'search' of undefined
instead.
why if don t execute?
edit: tried with
var pline { pline=gets(smil); if (pline===-1){console.log("abort");callback(-1);} console.log("line= "+pline); }while(pline.search("<video")===-1);
to avoid overriding variable, got same result
it's two-fer question.
1st - you're overwriting variable line
right after do
. that's why you're getting uncaught typeerror: object -1 has no method 'search'
change line parsed_line = gets(smil); //also never forget semicolons
2nd - search
isn't function of string, want indexof()
function.
so change while(line.search())
while(line.indexof())
.
i made fiddle demonstrates here
Comments
Post a Comment