Skip to Content
Test-Driven JavaScript Development
book

Test-Driven JavaScript Development

by Ravi Kumar Gupta
December 2015
Intermediate to advanced
240 pages
4h 57m
English
Packt Publishing
Content preview from Test-Driven JavaScript Development

has.js

has.js tests are very simple to perform and use has('feature') like syntax and return a Boolean value. The code in the previous example could be written as:

<script>
    var videoElement = "";
    $(document).ready(function(){
    if(has("video")){
        //  video is supported by the browser and can play it.
        $("#result").html("Video is supported");
        videoElement = document.createElement('video');
        $("body").append(videoElement);
    }else{
        // load via flash or something else
        $("#result").html("Video is not supported, use Flash or something else.");
    }
});
</script>

In this case, has("video") will return a Boolean value to help developer make a decision. Sometimes features are partially supported. To understand this, let's take the same example of displaying video ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Test-Driven JavaScript Development

Test-Driven JavaScript Development

Christian Johansen
Front-End Development Projects with Vue.js

Front-End Development Projects with Vue.js

Raymond Camden, Hugo Di Francesco, Clifford Gurney, Philip Kirkbride, Maya Shavin, Dániel Szabó

Publisher Resources

ISBN: 9781782174929Supplemental Content