1
<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.

1 Answer 1

1

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]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.