我有一个这样的课:
class Cow
@feet : 4
constructor: (@name) ->
bes = new Cow "Bessie"
Run Code Online (Sandbox Code Playgroud)
问题是,是否有可能只获得脚bes?
mu *_*ort 26
你可以使用JavaScript constructor属性来上课,你会发现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
?
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/ambiguous/ZfsqP/
我不知道有什么特别的CoffeeScript替代品constructor.