What does “function() { … }” do in an argument to setTimeout?
20:30 01 Apr 2011

Let's consider this piece of JavaScript:

function Person(name) {
    this.name = name;
}

Person.prototype.showName = function() {
    alert(this.name);
}


var mike = new Person("mike");
//mike.showName();  

window.name = "window"; 

I don't understand the difference between the behavior of

setTimeout(mike.showName(), 5000);

and

setTimeout(function(){
    mike.showName();
}, 5000);

Why is the behavior different? It really confuses me. Thanks.

javascript