How to structure utility class

前端 未结 5 699
深忆病人
深忆病人 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:23

    If you create a file utils.ts which contains

    export default class Utils {
        static doSomething(val: string) { return val; }
        static doSomethingElse(val: string) { return val; }
    }
    

    then you can simplify your client code like this:

    import Utils from './utils'
    
    export class MyClass {
         constructor()
         {
             Utils.doSomething("test");
         }
    }
    

提交回复
热议问题