3

고급 컴파일 모드에서 오류가 발생합니다. Google 폐쇄 이벤트 타겟은 어떻게 작동합니까?

Uncaught TypeError: Object #<d> has no method 'attachEvent' 

는 일부 소스지도 마법 후 나는이 첫 번째 인수 goog.events.EventTarget 상속, 내 사용자 정의 개체입니다 goog.events.listen 전화에서 발생되는 생각.

이 클로저의 소스

goog.events.EventTarget.prototype.addEventListener = function(
    type, handler, opt_capture, opt_handlerScope) { 
    goog.events.listen(this, type, handler, opt_capture, opt_handlerScope); 
}; 

에 그래서이 기능이

// Attach the proxy through the browser's API 
if (src.addEventListener) { 
    if (src == goog.global || !src.customEvent_) { 
    src.addEventListener(type, proxy, capture); 
    } 
} else { 
    // The else above used to be else if (src.attachEvent) and then there was 
    // another else statement that threw an exception warning the developer 
    // they made a mistake. This resulted in an extra object allocation in IE6 
    // due to a wrapper object that had to be implemented around the element 
    // and so was removed. 
    src.attachEvent(goog.events.getOnString_(type), proxy); 
} 

goog.events.listen에 다음 customEvent_ = true와 함께, 내 객체의 프로토 타입에 끝 (마지막 줄은 발생 하나입니다)

스택 오버플로가 발생하지 않아야합니까? 내 개체가 addEventListener에서 상속 받으면 else 분기로 들어가는 이유는 EventTarget입니까? 간단한 컴파일 모드에서는 모든 것이 잘 동작합니다. 이 방법은 어떻게 작동하며 고급 컴파일 모드에서만 오류가 발생합니까?

+0

개체의 실제 구현을 공유해주십시오. – zakelfassi

답변

1

코드를 더 추가 할 수 있습니까? 맞춤 이벤트는 어떻게 생겼습니까? 기본적으로 JS의 기본 'addEventListener'가 다시 작성됩니다. IE는 addEventListener를 구현하지 않고 attachEvent 만 반환하고 반환되는 이벤트 객체는 일반적인 이벤트는 아니지만 goog.events.BrowserEvent입니다.

고급 편집 모드에서 컴파일러는 이벤트 개체를 비롯한 모든 개체의 속성을 평평하게 만듭니다. 맞춤 이벤트의 속성이 고급 편집 모드에서 병합 될 수 있습니다 (이 경우가 대부분).이 경우 attachEvent()가 프로토 타입에 없습니다. 그것은 aE() 또는 이와 비슷한 것으로 될 수 있습니다. 누구든지 진짜 유용한 제안을 내놓기 전에 좀 더 많은 코드를 작성하십시오.

관련 문제