Skip to content

Instantly share code, notes, and snippets.

@curioustechizen
Created July 10, 2015 13:52
Show Gist options
  • Select an option

  • Save curioustechizen/98652aca149352c1fcc5 to your computer and use it in GitHub Desktop.

Select an option

Save curioustechizen/98652aca149352c1fcc5 to your computer and use it in GitHub Desktop.

Revisions

  1. curioustechizen created this gist Jul 10, 2015.
    24 changes: 24 additions & 0 deletions js_revealing_module_snippet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    "Revealing Module Pattern with constructor": {
    "prefix": "reveal",
    "body": [
    "var ${1:ModuleName} = (function () {",
    " var that,",
    " constr = function (${2:constr_param}) {",
    " that = this;",
    " this.$2 = $2;",
    " },",
    "",
    " ${3:privateFn} = function () {",
    " var temp = that.$2;",
    " };",
    "",
    " constr.prototype = {",
    " constructor: $1,",
    " $3: $3",
    " };",
    "",
    " return constr;",
    "})();"
    ],
    "description": "An implementation of revealing module pattern with a constructor"
    }
    18 changes: 18 additions & 0 deletions output.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    var ModuleName = (function () {
    var that,
    constr = function (constr_param) {
    that = this;
    this.constr_param = constr_param;
    },

    privateFn = function () {
    var temp = that.constr_param;
    };

    constr.prototype = {
    constructor: ModuleName,
    privateFn: privateFn
    };

    return constr;
    })();