理解するのに苦戦してます。
グローバルを汚さないために上手く使うのが通みたいです・・・
jQueryだと
;(function($){ //var apps = {};など //functionなど })(jQuery);
こんな感じで書き始めて、いろいろ処理を書き込んで行くのがいいみたいです。
(function(){ })();で即実行の無名関数なんだそうで。
試しにクラスを作ってみます。
;(function($) { var GW = (function() { // private static var count = 0, current, str = 'strの値です'; // constructor function GW() { console.log('コンストラクタです'); console.log(count); addCount(); this.init(); } // prototype GW.prototype = { test01 : 'test01です' } GW.prototype.options = {} GW.prototype.init = function() { console.log('prototype initです'); console.log(count); } GW.prototype.getCount = function() { console.log(count); return count; } GW.prototype.setCount = function(num) { count = num; console.log(count); } // static method var addCount = function() { count++; } return GW; })(); var instanceGW = new GW(); instanceGW.getCount(); instanceGW.setCount(2345); console.log(instanceGW.test01); })(jQuery);
少し理解できた気がする。