javascript - call static function in class in another helper function in the same file -


i have class in file contains static functions called in js files.

module.export = class myclass{   static create(){     ...   } }  // helpers  function callcreate(){   .. } 

i want call static function of myclass in callcreate helper function. how can this?

the static members of class accessed like:

class myclass {      property() {      console.log('i normal member');    }      static func() {      console.log('i static member');    }      static functhis() {      console.log('i static member');      console.log(this === myclass); // true      this.func(); // run fine static member of class      this.property(); // give error normal member of class    }    }    (new myclass()).property();    myclass.func();    myclass.functhis();

static members directly accessed class name , not linked object. also, can use static member of class inside of static function.

notice: pointed out @felixkling inside static function this refer directly class.

tip: use pascalcase naming class.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -