<commit_before>/**
 * CH. 03 - Object Patterns
 * Module Pattern
 *
 * JavaScript Patterns - modern JS patterns with ES5 & ES6 examples
 * @copyright 2016 - 2017, <NAME>
 * license: MIT
 */

/*
 * (i). To understand what a Module is, you’ll need to understand what an IIFE
 * can do for you and how it's constructed
 */

// a. Simple iife, or immediately invoked functional expression
(function() {
  // ...code here
})();

// b. Create a namespace for our code or anonymous module
var myModule = (function(idx) {
  idx.indexOf(idx);
  // ...code here
})();

/*
 * (ii.) Modules in JavaScript are used to create private and public encapsulation of classes - those
 * seen in conventional programming languages. the module pattern internalizes state and keeps code shielded
 * from the global scope, and potentially other libraries and variables that can collide with it.
 */

// a. So, to mimic a private method or property one has to only do this
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  }
})();

// b. Now we simply use the `return` statement to return an object literal to which
// we bind the methods we want to expose to the namespace. It's that simple
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  };

  // the return statement
  return {
    privateProp: privateProp,
    privateMethod: privateMethod
  }
})();

// b. Now we simply use the `return` statement to return an object literal to which
// we bind the methods we want to expose to the namespace. It's that simple
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  };
  // the return statement
  return {
    privateProp: privateProp,
    privateMethod: privateMethod
  }
})();

//. c. Perhaps a more readable variation could look like this
var Module = (function () {

  // locally scoped Object
  var myObject = {};

  // declared with `var`, must be "private"
  var privateMethod = function () {};

  myObject.someMethod = function () {
    // take it away Mr. Public Method
  };

  return myObject;

})();<commit_msg>Update module-pattern.js<commit_after>/**
 * CH. 03 - Object Patterns
 * Module Pattern
 *
 * JavaScript Patterns - modern JS patterns with ES5 & ES6 examples
 * @copyright 2016 - 2017, <NAME>
 * license: MIT
 */

/*
 * (i). To understand what a Module is, you’ll need to understand what an IIFE
 * can do for you and how it's constructed
 */

// a. Simple iife, or immediately invoked functional expression
(function() {
  // ...code here
})();

// b. Create a namespace for our code or anonymous module
var myModule = (function(idx) {
  idx.indexOf(idx);
  // ...code here
})();

/*
 * (ii.) Modules in JavaScript are used to create private and public encapsulation of classes - those
 * seen in conventional programming languages. the module pattern internalizes state and keeps code shielded
 * from the global scope, and potentially other libraries and variables that can collide with it.
 */

// a. So, to mimic a private method or property one has to only do this
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  }
})();

// b. Now we simply use the `return` statement to return an object literal to which
// we bind the methods we want to expose to the namespace. It's that simple
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  };

  // the return statement
  return {
    privateProp: privateProp,
    privateMethod: privateMethod
  }
})();

// b. Now we simply use the `return` statement to return an object literal to which
// we bind the methods we want to expose to the namespace. It's that simple
var aModule = (function() {
  var privateProp = 'Private Property';
  var privateMethod = function() {
    console.log('I\'m a private method');
  };
  // the return statement
  return {
    privateProp: privateProp,
    privateMethod: privateMethod
  }
})();

//. c. Perhaps a more readable variation could look like this
var Module = (function () {

  // locally scoped
  var myObject = {};

  // if it's declared with var, then it's private
  var privateMethod = function () {};

  myObject.someMethod = function () {
    // a public method
  };

  return myObject;

})();

{'fraction_non_alphanumeric': 0.11040664626147792, 'fraction_numerical': 0.005247048535198951, 'mean_word_length': 3.2282809611829943, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3608285', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1242, 'n_words': 565}