ssshooter
V2EX  ›  问与答

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

  •  
  •   ssshooter · Oct 12, 2021 · 1400 views
    This topic created in 1674 days ago, the information mentioned may be changed or developed.

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

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

    好像是可以 declare 的。但是这不就变成写代码和写类型分开了?那用 ts 的意义何在
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2404 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 16:12 · PVG 00:12 · LAX 09:12 · JFK 12:12
    ♥ Do have faith in what you're doing.