1

I was using a jQuery Framework and found code which is in the way below. Now: I understand that there is an IIFE and the return is giving an object containing several JSON/Functions. But I don't understand why the two vars are above the return? Is this some kind of private-member pattern because it cannot be accessed using the generator-variable? What kind of pattern is this? Thanks!!

$(document).ready(function() {
    var generator = (function() {

        var _eventhandler = function() {
            $('#id').keyup(function() {
                generator.validate(true);
            });
        }

        var _isAllowed= function() {
            return true;
        };

        return {
            config: {
                //config data
            },
            init: function() {
                console.log("init generator...");
            }
            validate: function {
                return true;
            }
        }
    }());

    generator.init();
});
joews
  • 29,767
  • 10
  • 79
  • 91
ChristianB
  • 63
  • 5
  • 2
    It's the [module pattern](https://toddmotto.com/mastering-the-module-pattern/). – joews Feb 06 '17 at 00:10
  • @joews hi , i just know it, WTF. i always ignore them like basic function. owh man.. its almost 4 years, and i still dont know this XD. anyway thanks for the questioner and the answerer – plonknimbuzz Feb 06 '17 at 00:14
  • Thanks joews for the answer. Basically the answer is yes: the vars above are private stuff, return stuff is public. Thanks! – ChristianB Feb 10 '17 at 02:52

0 Answers0