DOM構築前後両方でlog出力

これを雛形としてHTMLやらJavaScriptやらを書く。
scriptタグ内で「log('hogehoge');」とやるも良し(DOM構築前)、
イベントハンドラに登録した関数の中で「log('fugafuga');」とやるも良し(DOM構築後)。

<html>
<head>
<script>
(function(){
	var temp = [];
	
	log = function(s){
		temp.push(s);
	};
	function init(){
			if(typeof document.readyState != 'undefined' && document.readyState != 'loaded' && document.readyState != 'complete'){
				setTimeout(arguments.callee,100);
				return;
			}
			var div = document.createElement('div');
			div.id = 'log';
			for(var i = 0;i < temp.length;i++){
				div.appendChild( document.createTextNode(temp[i]) );
				div.appendChild( document.createElement('br') );
			}
			
			document.body.appendChild(div);

			log = function(s){
				div.appendChild( document.createTextNode(s) );
				div.appendChild( document.createElement('br') );
			};
	}
	if(typeof document.readyState == 'undefined' && document.addEventListener){
		document.addEventListener('DOMContentLoaded',init, false );
	}else{
		init();
	}

})();
</script>
</head>
<body>
</body>
</html>

これ勘違いだったっぽい

以下、作ってる最中にTwitterでメモったこと

monjudoh FirefoxIEでは setTimeoutが必ずdocument構築後に実行されるけど、Operaだとそうとは限らないのか
monjudoh setTimeout(someFunction, 1);だとOperaでもdocument使用可能なタイミングで実行されるようだ。setTimeout関数実行直前からsomeFunction実行時までの経過時間は1msではないのでdocument使用可能になるまで待っているようだ。