In Javascript, any function is also an object, so any function can have properties assigned to it. This is what your first block of code does. It simply sets the properties of the CookieHandler function. If CookieHandler is understood as a definition of an object, then although not quite identical, they are similar to the static properties of a class in other OO languages.
If this does not mean defining an object, then the CookieHandler is similar to the Javascript namespace, and getCookie and setCookie are similar to the properties in this namespace.
The second block of code assigns properties to the prototype. These properties will be inherited by the cookieHandler instance.
So, with your first block of code:
var CookieHandler = function () {}; CookieHandler.getCookie = function (key) { }; CookieHandler.setCookie = function (key, value) { };
You can simply call CookieHandler.getCookie() freely at any time. CookieHandler is a namespace object, and getCookie and setCookie are properties in the namespace.
If you create a CookieHandler, for example:
var x = new CookieHandler(); x.getCookie(); // does not work x.setCookie(); // does not work
Then x does not have getCookie() or setCookie() methods. These methods exist only in the CookieHandler object. They are not inherited by CookieHandler instances.
With your second block of code:
var CookieHandler = function () {}; CookieHandler.prototype.getCookie = function (key) { }; CookieHandler.prototype.setCookie = function (key, value) { };
you define properties that inherit CookieHandler instances (instances inherit prototype properties). So when you do this:
var x = new CookieHandler(); x.getCookie();
So, use prototype when you want to define properties (usually methods) that inherit object instances. If you are not trying to define instance methods, simply install the methods on any object, as in the first block of code.