CPSC415A
Web Programming

Day 12 Notes

Namespaces and Cookies

Namespace

var namespace = {};
namespace.globalVariable = 3;
namespace.functionName = function() {
    namespace.globalVariable--;
    if (namespace.globalVariable > 0) {
        return namespace.funcionName();
    }
    return Math.random();
};

Cookies

document.cookie = 'namespace-globalVariable=' + namespace.globalVariable;
document.cookie = 'namespace-globalVariable=' + namespace.globalVariable +
                  '; expires=Fri, 31 Dec 9999 23:59:59 GMT';
var daysUntilExpiration = -1;
var expirationDate = new Date(Date.now() + daysUntilExpiration * MILLISEC_IN_DAY);
document.cookie = 'namespace-globalVariable=' + namespace.globalVariable +
                  '; expires=' + expirationDate;
document.log(document.cookies);