oop - Create private static function in Javascript? -


i'm using following code create: private property, private method, public property, public method , public static property.

function classa() {      var privateproperty = 'private_default_value';      var privatemethod = function() {         console.log("private method executed ...");     };      this.publicproperty = 'public_default_value';       this.publicmethod = function() {         console.log("public method executed ...");     };      classa.publicstaticproperty = "public_static_default_value";      // how create here: classa.privatestaticproperty ?  };  var instance = new classa(); instance.publicmethod(); console.log(classa.publicstaticproperty); 

how can create private static property in class ?

here's solution using iife create scope visible the constructor classa :

var classa = (function(){      var constructor = function(){         var privateproperty = "private_default_value";          var privatemethod = function() {             console.log("private method executed ...");         };          this.publicproperty = "public_default_value";           this.publicmethod = function() {             console.log("public method executed ...");         };     }     constructor.publicstaticproperty = 'public_static_default_value';     var privatestaticproperty = "private_static_default_value";      return constructor; })(); 

privatestaticproperty "static" : there's 1 property.

privatestaticproperty "private" : can't read outside iife.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -