Example 1:
function a(){
return "ok";
}
function b(){
this.c = a;
}
var d = new b();
alert(d.c()); // Result "ok".
Example 2:
function b(){
this.c = a();
}
var d = new b();
alert(d.c); // Result "ok".
What do the parentheses mean in this case?
Putting
()after a function calls it – causing the function to be executed. In your examples, the function isa.Your two cases can be thought of as:
Example 1
Example 2
In either case the function
ais being called with()exactly once – hence they produce the same output.