what's the different between calling functions with () or without ()
hi , i have really big problem in understanding this .
let say i have an object and my objects contain couple of functions
var my_methods = {
init:function(){
$(window).load(my_methods.create_element());
$(window).click(my_methods.window_clicking);
},
create_element:function(){
//some code
},
window_clicking:function(){
alert('hello world');
}
}
the both of the above functions calling w'll works pretty fine , but the problem is that if i'm using () it w'll call the function like calling function's simply but if i don't use () (in second line) it w'll not calling the function it'll attach the handler to the event .
so if i use
$(window).click(my_methods.window_clicking());
it'll works just for one time and trigger out immediately.
is my explanation correct or i'm a little wrong . of what i.m saying.
and i'll thank you if you show me example .