OpenLayers의 객체 시스템은 initialize()라는 함수를 생성자로 사용하므로 OpenLayers 클래스를 확장 할 때 CoffeeScript의 super 키워드가 올바르게 작동하도록하려면 다음을 수행해야합니다. 그들을 장식하십시오. 나는이에 대해 다음 함수를 사용
window.CompatibleClass = (cls) ->
class Wrapped
constructor: ->
# Call the OpenLayers-style constructor.
cls::initialize.apply @, arguments
# Copy prototype elements from OpenLayers class.
Wrapped::[name] = el for name, el of cls::
Wrapped
지금 당신이 내장 그래서 같은 OL을 확장 할 수
class MySpecialFeature extends (CompatibleClass OpenLayers.Feature.Vector)
constructor: ->
super new OpenLayers.Geometry.Point 0, 0
CLASS_NAME: "MySpecialFeature"
편집 : 그냥 클래스를 포장하기 위해, 두 가지 대안을 명확히 이런 식으로 OpenLayers 클래스 시스템을 그대로 사용하고 CoffeeScript의 문법 이점 중 일부를 놓치거나 각 생성자에서 수동으로 initialize 함수를 호출하는 것이 있습니다.이 함수는 더 부서지기 쉬우 며 의존성을 중심으로 확산됩니다. 그것은 하나의 장식 자입니다.
MySpecialFeature = OpenLayers.Class OpenLayers.Feature.Vector,
initialize: ->
# Call super using apply, as is convention in OpenLayers
OpenLayers.Feature::initialize.apply @, new OpenLayers.Geometry.Point 0, 0
...
...
달리, 커피 스크립트 클래스를 사용하지만 OpenLayers 클래스 않은 장식 연장 : 커피 스크립트에있는 그대로 OpenLayers 클래스 시스템을 사용
class MySpecialFeature extends OpenLayers.Feature.Vector
constructor: ->
# Call inherited initialize().
@initialize.apply @, new OpenLayers.Geometry.Point 0, 0
...
...
이러한 방법 중 어느 것 오픈 레이어 (OpenLayers) 또는 커피 스크립트 (CoffeeScript) 중 하나 인 다른 개발자들에게는 관용적이거나 인식할만한 사람이어야합니다. OpenLayers 생성자를 호출 할 때 네이티브 super() 사용을 허용하는 래퍼를 추천합니다.
awesome! 나는 지금이 물건을 찾는 것만 믿을 수 없다. –