serv/copyright.js — pull request #1 by richardcornish (2014-01-08 04:05:00+00:00)
Title: Rewrote plugin in a namespaced function constructor pattern, edited README

Main change was moving code from a simple object pattern to a function constructor pattern inside an immediately invoked function expression.

The key-value `components` object was hanging out in the global namespace. That's one of the "almost absolute" rules of JavaScript that shouldn't be broken. Scripts written by others might include the global variable `components`, causing collisions and errors. The remedy is an immediately invoked function expression (IIFE). Wrap your script inside a function without a name, include the invocation parentheses, and then wrap all that up in another set of parentheses. The script is immediately invoked, waiting on the `DOMContentLoaded` event to fire. More on IIFEs: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

The big other change was moving from a key-value object to a function constructor. This is a slightly more controversial change. Hanging methods off of an object isn't exactly *bad* but it can likely be improved. When the object is called (previously `components.init()`), the object's attached methods are loaded into memory. If you were to invoke `components.init()` more than once, the object and its methods are loaded again into memory. Repeated calls would cause memory to run out depending on the browser because of the different ways garbage collection is handled. The remedy is to rewrite the object into a function constructor. The function constructor is the same as a function except that objects are created from it with the `new` keyword, which is used when the `DOMContentLoaded` event is fired. The result is the same as a key-value object literal but with the ability to hang methods on it with the object's built-in `prototype` attribute. Hanging methods with `prototype` allows you to add more methods without garbage collection issues.

Obviously your script is meant to run once, so it's not much of an issue. Both scripts do the same thing and both work. The function constructor might be unnecessary, but over time I've tried to move to either the constructor or the namespace module pattern in my code, and I feel like it's sturdier. It's also more verbose, so that's a tradeoff that you'll have to decide for yourself.

Other changes include using newer and native DOM methods, error handling on IDs, README edits, and the use of `this` to replace `components`, which is whatever the name of the current object is and is a best practice.