How to structure utility class

前端 未结 5 700
深忆病人
深忆病人 2020-12-12 19:48

I have several utility functions. What is the best way to package these up, and then import them?

This is what I am trying to do:

import * as util f         


        
5条回答
  •  無奈伤痛
    2020-12-12 20:03

    Alternative way:

    1. Export constants in your utils.ts file:

      export const doSomething = (val: string): any => {
        return val;
      };
      
      export const doSomethingElse = (val: string): any => {
        return val;
      };
      
    2. Import and use this methods in main *.ts file:

      import { doSomething, doSomethingElse } from './util';
      ...
      let value1 = doSomething('abc');
      let value2 = doSomethingElse ('efg');
      

提交回复
热议问题