2012-11-17 2 views

답변

1

이 문제는 CoffeeScript가 수업을 작성하는 방식과 Google지도 자바 스크립트 API가 작성/난독 화/축소되는 방식의 조합입니다.

customnamespace.CustomMap = (function(_super) { 

    // '__extends' is a method that gets output at the 
    // top of every CoffeeScript compiled file 
    __extends(CustomMap, _super); 

    function CustomMap(mapDiv, opts) { 
     CustomMap.__super__.constructor.apply(this, arguments); 
    } 

    return CustomMap; 

})(google.maps.Map); 

대부분의 경우, 특히 "extendee는"커피 스크립트로 작성된 경우,이 위대한 작품을 : 커피 스크립트는 클래스를 확장 할 때

는,이 같은 코드 뭔가를 만듭니다.

그러나 google.map.Maps의 경우에는 (나는 의심 스럽습니다) 범위 조작이 진행되고 CoffeeScript가 설정하려고하는 범위를 실행 취소해야합니다. 틀림없이 이것은 추측입니다.

그래서이 경우에는 JavaScript 모자를 사용하고 생성자에 대한 평범한 이전 스코프 잠금을 수행해야합니다. 따라서 superapply 함수를 자바 스크립트 행이있는 클래스의 범위에 드롭하십시오. CoffeeScript는 흔들리지 않고 미소 짓고 그대로 JavaScript 줄을 출력합니다.

class MyMap extends google.maps.Map 
    constructor: (mapDiv, opts)-> 
     google.maps.Map.apply(this, [mapDiv, opts]); 

의미가 있습니까?

+0

감사합니다. 비슷한 솔루션을 사용했습니다. google.maps.Map.call (this, $ ('map_canvas') [0], opts) – mahnunchik