Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Test-Driven JavaScript Development

You're reading from   Test-Driven JavaScript Development Learn JavaScript test-driven development using popular frameworks and tools

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781782174929
Length 240 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ravi Kumar Gupta Ravi Kumar Gupta
Author Profile Icon Ravi Kumar Gupta
Ravi Kumar Gupta
Arrow right icon
View More author details
Toc

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 content. We can check if a video tag is supported or not, but this is not sufficient as we might need to play a certain format like Ogg, Mp4, MKV, and so on. We need to...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime