JSFiddle - React, Tailwind, and code Playground

by Kai

HTML

<div id="results"></div>

JavaScript

(function ($) {
    var $div = $('#results'); // Def
    
    $.getJSON("http://api.justin.tv/api/stream/list.json?category=gaming&jsonp=?", function (json) {
        // We are now in an anon func, called way after the function that defines $div ended.
        // Doesn't matter, we still have access to all vars defined in it (closure)
        
        $div.html('Waiting 5 seconds...');
        
        setTimeout(function () { // Wait five seconds before we do anything.
            $.each(json, function (key, val) {
                // We're in another anon func within a setTimeout's anon func. 
                // However, we have access to everything our parent func (setTimeout)
                // had access to, which has access to everything its parent has access to
                
                $div[0].innerHTML += key + '<br/>'; // and we can still see $div
            }); 
         }, 5000);
    });
}(jQuery));