Question

<script src="modernizr-1.7.min.js"></script>    
var modernizr_fields = new Array("canvas","video","webgl");     
for (i=0; i < modernizr_fields.length; i++) {
    document.writeln(modernizr_fields[i] + " ");    
    if (Modernizr + "." + modernizr_fields[i])
        document.writeln("true");   
    else
        document.writeln("false");
    document.writeln("<br>");       
}

I know the problem is with this line: "if (Modernizr + "." + modernizr_fields[i])" as it is always evaluating to "true"

Please help with my syntax.

Was it helpful?

Solution

You need:

if (Modernizr[modernizr_fields[i]]) {
     ...
}

The format obj.field only works with literal field names, if field is instead a variable you have you use obj[field]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top