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
Post a Comment