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

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

  •  
  •   ssshooter · 2021-10-12 17:22:49 +08:00 · 784 次点击
    这是一个创建于 898 天前的主题,其中的信息可能已经有所发展或是发生改变。

    例如这样的 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
    wunonglin
        1
    wunonglin  
       2021-10-12 17:39:44 +08:00
    是。

    好像是可以 declare 的。但是这不就变成写代码和写类型分开了?那用 ts 的意义何在
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1404 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:35 · PVG 01:35 · LAX 10:35 · JFK 13:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.