프로젝트 용으로 coffeescript를 쓰고 있는데 클래스에 일부 정적 속성을 만들려고합니다. 나는 같은 일을 성공적으로 수행하는 코드베이스의 또 다른 파일을 따라 왔지만, 내 것이 작동하지 않는다.CoffeeScript에서 정적 속성과 관련하여 문제가 발생했습니다.
내 코드
class Messages
@toggleUnreadConversations:()->
# This is the line in question, Messages is defined with all the
# functions but the property ViewOnlyUnread is undefined
Messages.ViewOnlyUnread = !Messages.ViewOnlyUnread
@init:->
@ViewOnlyUnread = false
성공적으로 사용하는 코드베이스
다른 코드 정적 속성
같은 방법으로 호출되고 난이 초기화하기 기능을 무엇을 말할 수에서class Map
@CacheRealtor: (realtor) ->
realtor.realtor_id = parseInt(realtor.realtor_id)
# Here the static property IdToRealtorMap is defined
Map.IdToRealtorMap[parseInt(realtor.realtor_id)] = new Realtor()
@Init: ->
@IdToListingMap = []
@IdToRealtorMap = []
, 페이지가로드 init가 호출됩니다. 두 클래스 모두 정적 클래스이며, 둘 중 하나의 인스턴스가 생성되지 않습니다. 누구든지 문제가 될 수있는 아이디어가 있습니까?
무엇을 작동하지 않습니다
당신은
init
세트가있는 인스턴스 변수를 참조 할@
를 사용해야합니까? – robkuz해당 코드 줄이 실행될 때 Messages.ViewOnlyUnread는 undefined로 평가됩니다. – Mike