V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ssshooter
V2EX  ›  问与答

Typescript 中,如果以 prototype 而不是 class 进行面向对象编程,是不是寸步难行?

  •  
  •   ssshooter · 2021 年 10 月 12 日 · 1265 次点击
    这是一个创建于 1553 天前的主题,其中的信息可能已经有所发展或是发生改变。

    例如这样的 js 代码怎么转换成 ts ?

    import function1 from './otherside'
    import function2 from './otherside2'
    function Klass(){
    	this.a = 1
    }
    Klass.prototype = {
        local:function(xxx){},
        function1,
        function2,
    }
    
    1 条回复    2021-10-12 17:39:44 +08:00
    shakaraka
        1
    shakaraka  
    PRO
       2021 年 10 月 12 日
    是。

    好像是可以 declare 的。但是这不就变成写代码和写类型分开了?那用 ts 的意义何在
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1028 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:50 · PVG 06:50 · LAX 14:50 · JFK 17:50
    ♥ Do have faith in what you're doing.