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