[answered]
HTML5 ゲームのブラウザの fps をテストしています。
私はこのコードを持っています:
var requestAnimationFrame = ( function() {
return window.requestAnimationFrame || //Chromium
window.webkitRequestAnimationFrame || //Webkit
window.mozRequestAnimationFrame || //Mozilla Geko
window.oRequestAnimationFrame || //Opera Presto
window.msRequestAnimationFrame || //IE Trident?
function(callback) { //Fallback function
window.setTimeout(callback, 1000/60);
}
})();
var hits = 0;
var last = new Date().getTime();
var step = (function(){
now = new Date().getTime();
hits += 1;
if( now - last >= 1000 ){
last += 1000;
console.log( "fps: "+ hits );
hits = 0;
}
requestAnimationFrame( step );
})();
Chrome で次のエラーが発生します:
Uncaught Error: TYPE_MISMATCH_ERR: DOM Exception 17
行番号 27:requestAnimationFrame( step );
W3 は、このエラーは次If the type of an object is incompatible with the expected type of the parameter associated to the object.
のように述べています。window
しかし、割り当てられた無名関数の呼び出し括弧を削除しstep
、代わりにその関数を宣言し、新しい行に次のように記述した場合:
step();
できます。
どうしてこれなの?
どちらも同じように機能するべきではありませんか?