어떤 컨텐트가 다 읽혔는지 비동기적으로 확인하기 위해서 setTimeout 을 호출해본 적이 있습니까? 그런 일은 꽤 자주 일어나는 편인 것 같습니다. Paul Irish씨가 필요한 라이브러리가 읽힌 후에 코드를 실행할 수 있도록 도와주는 간단한 유틸리티를 작성했습니다.
그의
from Polling for loaded content instead of simple setTimeout on Ajaxian
그의
executeWhenLoaded(function, objects, that, must, be, present)
를 이용해 이런 식으로 사용할 수 있습니다:[code:js]
executeWhenLoaded(function(){
console.log(session.data);
}, 'session'); // session will return a value when the whatever preceding functionality is done.
구현은 간단하게 되어있습니다:executeWhenLoaded(function(){
console.log(session.data);
}, 'session'); // session will return a value when the whatever preceding functionality is done.
[code:js]
function executeWhenLoaded(func){
for (var i = 1; i<arguments.length; i++){ // for loop starts at 1 to skip the function argument.
if (! window[ arguments[i] ]) {
setTimeout(arguments.callee,50);
return;
}
}
func(); // only reaches here when for loop is satisfied.
}
function executeWhenLoaded(func){
for (var i = 1; i<arguments.length; i++){ // for loop starts at 1 to skip the function argument.
if (! window[ arguments[i] ]) {
setTimeout(arguments.callee,50);
return;
}
}
func(); // only reaches here when for loop is satisfied.
}
from Polling for loaded content instead of simple setTimeout on Ajaxian
'[IT] Web Tech' 카테고리의 다른 글
Doctype: 테스트해보실래요? (0) | 2008.05.22 |
---|---|
Flash 10 "Astro" 프리릴리스 (0) | 2008.05.22 |
MooTools를 이용한 CSS 애니메이션 (2) | 2008.05.20 |
Google Doctype : 개방형웹의 문서화! (0) | 2008.05.20 |
단순한 setTimeout 대신 Polling (0) | 2008.05.20 |
xmake : JavaScript로 만든 make 같은 유틸리티 (0) | 2008.05.20 |
Timelapse CSS : 시간이 보이는 CSS (0) | 2008.05.20 |
window.name에는 뭐가 있을까? (0) | 2008.05.20 |
inputEx : JSON form builder (0) | 2008.05.20 |
댓글을 달아 주세요