Basic codes main.js:
class Something {
static ThisIsStaticFunction () { ... }
}
export default Something;
Other file xxx.js:
import xxx;
// I want to call `ThisIsStaticFunction()` without having to
// write `Something.ThisIsStaticFunction()` how can I achieve this?
I want to call ThisIsStaticFunction()
without having to write Something.ThisIsStaticFunction()
how can I achieve this?
You can alias the static function as a normal function
export const ThisIsStaticFunction = Something.ThisIsStaticFunction;
export default Something;
import {ThisIsStaticFunction}, Something from 'xxx';
Usually in Javascript (unlike Java) you can use plain function over static function.
export function ThisIsAFunction() {}
export default class Something {
instanceMethod() {
const result = ThisIsAFunction();
}
}
import {ThisIsAFunction}, Something from 'xxx';
const foo = ThisIsAFunction();
const bar = new Something()
const biz = bar.instanceMethod();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With