Anonymous Functions

Benchmark created by ahmadreza Azizan on


Setup

var bd = document.body ; 
    var evt = ['onclick','onkeypress'];
    
    
    function BindEvent (type){
    bd[type] = function(event){
    console.log(event.type);
    }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Anonymous Functions
for(var i in evt){
(function(){
bd[evt[i]] = function(event){
console.log(event.type);
}
})();
}
ready
Named Function
for(var i in evt){
BindEvent(evt[i]);
}
ready
another Named Function
for(var i in evt){
var fn = function (type){
bd[type] = function(event){
console.log(event.type);
}
}
fn(evt[i]);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by ahmadreza Azizan on