Javascript: self-executable classes and public functions -


i have lot of following classes:

(function() {    if (!window.administration) {      window.administration = {};    }    window.administration.customers = (function() {       // code , private methods       return {       // public methods       };    })(); })(); 

i heard somewhere such declarations of public methods not because js engines create many instances of public methods called them code... true?

in case how can refactor code in order solve such memory leaks leave self-executable feature?

thank you

you use construct instead if you're worried hiding methods:

(function(ns) {      // default constructor     ns.blah = function(v) {         this.v = v;         setup.call(this); // invoke private method     }      // private method, invoked using .call(this)     function setup()     {         this.w = this.v + 123;     }      function myhello()     {         return 'w = ' + this.w + ' , v = ' + this.v;     }      ns.blah.prototype = {         hello: function() {             return myhello.call(this);         }     };  }(window.myns = window.myns || {}); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -