1
어떻게 기존 함수 위에 함수를 추가 할 수 있습니까?"RangeError : 최대 호출 스택 크기 초과"오류 받기
나는 다음과 같은 방법을 사용하고 있는데이 var
키워드를 접두사로, resources.onload
resource = document.getElementById(this.id);
if (resource && resource.getAttribute('data-loading'))
{
onloadOthers = resource.onload;
onloadThis = this.onComplete.bind(this);
//following line give error
resource.onload = function() { // callback loops again and again!!!!!!
if (typeof onloadOthers == "function")
onloadOthers();
onloadThis();
};
return; // just added another callback, no need to add it again.
}
else if (resource)
{
this.onComplete();
return; // already exist
}
if (this.type == "js")
{ //if filename is a external JavaScript file
var code = document.createElement('script');
code.setAttribute("type", "text/javascript");
code.setAttribute('data-loading', 'yes');
code.setAttribute("src", this.file);
code.onload = this.onComplete.bind(this);
code.onreadystatechange = code.onload; // ie fix
}
오류는 대개 끝이없는 루프를 의미합니다. – HMR
예. 알고 있습니다. 내가 어떻게 고칠 수 있니? 새로운 콜백 위에 이전 콜백을 추가하고 싶습니다. 그래서 그들은 둘 다 온로드를 유발합니다. – Basit
'onloadOthers'는 무한 재귀를 일으킬 수 있습니다. 'unloadOthers' 변수가 새로운 클로저에 포함되어 있는지 확인하십시오. –