Last Updated: December 26, 2018
·
752
· yckart

Javascript Module

A quick look into my way of creating modules:

/**
  * A simple example how I structure my modules in javascript
  *
  */
var Module = (function () {


  /**
   * This is the `constructor` of our `Module`
   *
   */
  var Module = function (options) {

    // define some default options
    this.options = {
      key: 'value'
    };

    // merge the `options` with our defaults
    for (var key in options) {
      this.options[key] = options[key];
    }

  };


  /**
   * This is a `method` of or `Module`
   *
   */
  Module.prototype.method = function () {

  };

  return Module;

}());

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside