JS Module pattern with jquery

// JavaScript boilerplate (function (window, document, $) { "use strict"; var myModule = function () { var privateObject, privateMethod = function () { console.log('private') }; return { publicMethod : function () { console.log('public'); // private methods can only be used within their parent module scope privateMethod(); }, init: function () { console.log('Init!'); } }; }; $(function () { var module = new myModule(); module.init(); // calling the public method needs a new instance of the module module.publicMethod(); }); }(window, document, jQuery));

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.