分析JS代码在客户端抓取cookie

Analyzing JS code to grab a cookie at client-side

初学JS,正在分析一段很长的程序代码。我无法理解这个函数,除了它试图从客户端获取 cookie。谁能指出这里的功能?

function get_cookie(a) {
        var b = a + "=";
        var c = "";
        if (document.cookie.length > 0) {
             offset = document.cookie.indexOf(b);
             if (offset != -1) {
                 offset += b.length;
                 end = document.cookie.indexOf(";", offset);
                 if (end == -1) {
                     end = document.cookie.length;
                }
                c = unescape(document.cookie.substring(offset, end));
            }
        }
        return c;
    }
function get_cookie(a) {
        var b = a + "="; // Getting argument a and assigning it to var b appending =
        var c = ""; // defining variable c  
        if (document.cookie.length > 0) {  //checking cookie length in browser
             offset = document.cookie.indexOf(b);  // checking b exists or not
             if (offset != -1) { // if b exists 
                 offset += b.length; // getting no of string and assigning it to offset
                 end = document.cookie.indexOf(";", offset); //checking if ';' is present
                 if (end == -1) { // if ';' is not there in cookie string, 
                     end = document.cookie.length; - // cookie is not set, SO assigning length to the variable end
                }
                c = unescape(document.cookie.substring(offset, end)); // assigning those values to c
            }
        }
        return c; // returning new cookie.
    }