Quick Post: My JS File Template

I use PHPStorm for all my JavaScript needs. Dang it’s good. Anyway, I’ve been working on a secret JS project I’ll hopefully share one day, and one thing I’ve been working on is my JS file template. There’s not a lot to it, but this is what mine looks like:

 * Author: thegoldenmule
 * Date: ${DATE}

(function(global) {
    "use strict";

    var ${NAME} = function() {
        var scope = this;

        return scope;

    ${NAME}.prototype = {
        constructor : ${NAME}

    // export
    global.${NAME} = ${NAME};

Just a couple things: I like wrapping my whole definition in a closure. This is both a safeguard against my own accidental globals (yes, even thegoldenmule accidentally creates a global), and a safe space to stick “static” functions and objects, or even whole internal object definitions.

Inside the constructor function, I use the common pattern of defining a reference that points to this and returning that at the end.

The prototype is straightforward, as is the exports at the end. A cool caveat is that it’s really easy to then export for Node.