yqyq1020
V2EX  ›  问与答

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

  •  
  •   yqyq1020 · Dec 15, 2012 · 5558 views
    This topic created in 5073 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
    qiukun
    Dec 15, 2012
    1
    哪有类继承
    yqyq1020
    yqyq1020
    OP
    Dec 15, 2012
    2
    @qiukun 就是只是用prototype原型来模拟类?
    liaa
    liaa
    Dec 15, 2012
    3
    @yqyq1020 其实这种时候能用英语名词来提问或者直接贴出代码,获得准确答案的可能性会更高。
    yqyq1020
    yqyq1020
    OP
    Dec 15, 2012
    5
    @synzhang 我看到网上有很多的标题是js的类式继承和原型继承,讲的好像是两种继承方式,但我看了代码没有看出有什么区别,似乎就是用prototype原型来模拟其他语言中的类式继承,请问是不是这样的
    qiukun
    qiukun
    Dec 15, 2012
    6
    chone
    chone
    Dec 15, 2012
    7
    js原生的是原型继承,类继承是模拟出来的。
    watana
    watana
    Dec 15, 2012
    8
    《JavaScript Patterns》

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

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