module-pattern

Strict Violation using this keyword and revealing module pattern

别来无恙 提交于 2019-11-26 15:47:29
问题 Having trouble getting the following to pass jslint/jshint /*jshint strict: true */ var myModule = (function() { "use strict"; var privVar = true, pubVar = false; function privFn() { return this.test; // -> Strict violation. } function pubFn() { this.test = 'public'; // -> Strict violation. privFn.call(this); // -> Strict violation. } return { pubVar: pubVar, pubFn: pubFn }; }()); myModule.pubFn(); I understand it's being caused by the use of this in a function declaration, but I read

Define Private field Members and Inheritance in JAVASCRIPT module pattern

依然范特西╮ 提交于 2019-11-26 10:02:42
问题 I can define private member fields in module pattern using the code below var myClass = function(){ var private_field1,private_field_2; var private_func1 = function(){ //....... } //......... var myObj = { global_field1:2, global_field2:\"something\", global_func: function(){//......} } return myObj; }; var obj = myClass(); This method works just fine, but the problem with this problem is that whenever I create a new object the copy of all the functions is created and loaded in memory (not

JavaScript design pattern: difference between module pattern and revealing module pattern?

一个人想着一个人 提交于 2019-11-26 04:37:50
问题 I\'m reading the book Learning JavaScript Design Patterns recently. What I don\'t get is the difference between module pattern and revealing module pattern. I feel they are the same thing. Anyone can give an example? 回答1: There are at least three different ways to implement the Module Pattern, but the Revealing Module Pattern is the only Module Pattern descendant that has an official name. The Basic Module Pattern The Module Pattern must satisfy the following: Private members live in the