yqyq1020
V2EX  ›  问与答

js中类式继承和原型继承有什么区别

  •  
  •   yqyq1020 · Dec 15, 2012 · 5112 views
    This topic created in 4898 days ago, the information mentioned may be changed or developed.
    初学js,求解释
    Supplement 1  ·  Dec 15, 2012
    我看到网上有很多的标题是js的类式继承和原型继承,讲的好像是两种继承方式,但我看了代码没有看出有什么区别,似乎就是用prototype原型来模拟其他语言中的类式继承,请问是不是这样的
    9 replies    1970-01-01 08:00:00 +08:00
    qiukun
        1
    qiukun  
       Dec 15, 2012
    哪有类继承
    yqyq1020
        2
    yqyq1020  
    OP
       Dec 15, 2012
    @qiukun 就是只是用prototype原型来模拟类?
    liaa
        3
    liaa  
       Dec 15, 2012
    @yqyq1020 其实这种时候能用英语名词来提问或者直接贴出代码,获得准确答案的可能性会更高。
    yqyq1020
        5
    yqyq1020  
    OP
       Dec 15, 2012
    @synzhang 我看到网上有很多的标题是js的类式继承和原型继承,讲的好像是两种继承方式,但我看了代码没有看出有什么区别,似乎就是用prototype原型来模拟其他语言中的类式继承,请问是不是这样的
    qiukun
        6
    qiukun  
       Dec 15, 2012
    chone
        7
    chone  
       Dec 15, 2012
    js原生的是原型继承,类继承是模拟出来的。
    watana
        8
    watana  
       Dec 15, 2012
    《JavaScript Patterns》

    > Often you hear the term "classical inheritance" in discusstions on ...
    > ...
    > The term is just a play on the word "class".

    当时看到这句话,原来老美也会玩弄文字。。
    duhastmich
        9
    duhastmich  
       Dec 16, 2012
    @yqyq1020 可以看一下coffeescript的extends是怎么实现的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3228 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 13:27 · PVG 21:27 · LAX 06:27 · JFK 09:27
    ♥ Do have faith in what you're doing.