javascript access class method without initializing object -


i have class foo, can access public method bar out initializing fooobj

var foo = function(){    this.bar = function(){        console.log("i bar");    } } 

i know can access bar

var fooobj = new foo(); fooobj.bar(); 

in other object oriented language javeif declare bar static can access class name foo.bar

there no static concept java can like

var foo = function(){    // constructor specific code }  foo.bar = function(){     console.log("i bar"); } 

this how singleton defined in javascript


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -