Private “functions” in TypeScript

前端 未结 3 366
梦谈多话
梦谈多话 2020-12-02 14:55

Is it possible to create a private \"function\" (method) within a TypeScript class? Let\'s assume we have the following Person.ts TypeScript file:



        
3条回答
  •  被撕碎了的回忆
    2020-12-02 15:34

    In Javascript (as opposed to TypeScript), you can't have a private "member" function.

    If you define a private function in the closure, you won't be able to call it as an instance method on an instance of your class.

    If that's what you want, just move the TypeScript function definition outside the class body.

提交回复
热议问题