2012-03-01 63 views

回答

25

您可以使用JavaScript constructor property得到的类别,而且你会发现你feet

class Cow 
    @feet: 4 
    constructor: (@name) -> 

class HexaCow extends Cow 
    @feet: 6 

bes = new Cow('Bessie') 
pan = new HexaCow('Pancakes') 

alert(bes.constructor.feet) # 4 
alert(pan.constructor.feet) # 6 
​ 

演示:http://jsfiddle.net/ambiguous/ZfsqP/

我不知道任何特殊的CoffeeScript更换为constructor的,虽然。