14
에서 클래스의 인스턴스에서 클래스 변수에 도착이 같은 클래스 :내가 가진 커피 스크립트
class Cow
@feet : 4
constructor: (@name) ->
bes = new Cow "Bessie"
문제가있다 그것은 단지 bes
주어 발에 액세스 할 수 있습니까?
에서 클래스의 인스턴스에서 클래스 변수에 도착이 같은 클래스 :내가 가진 커피 스크립트
class Cow
@feet : 4
constructor: (@name) ->
bes = new Cow "Bessie"
문제가있다 그것은 단지 bes
주어 발에 액세스 할 수 있습니까?
당신은 클래스에서 얻을 수있는 자바 스크립트 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/
그래도 난 constructor
에 대한 특별한 커피 스크립트 교체 모르겠어요 .