Jump to content

method();


Drycodez

Recommended Posts

the you wouldn't be calling it. that's part of their significance. In your snippet, if method is a function object, then call is now equal to the value of method.i.e.

var method = function(){  alert('sup');};var call = method;call();  //alerts 'sup'

Link to comment
Share on other sites

No, you cannot call a function without the parens. When you use a function name without the parens, you are simply using a reference to the function. Script like what you posted assigns the reference to another variable. You could then use that variable name to call the function too.

function someFunction(msg) {   alert(msg);}var showMsg = someFunction;//Either of these will workshowMsg('This is a test.');someFunction('This is a test.');

I can't think of any specific examples right now of where this would be useful, but perhaps someone else might pop in and provide a few.

Link to comment
Share on other sites

No, you cannot call a function without the parens. When you use a function name without the parens, you are simply using a reference to the function. Script like what you posted assigns the reference to another variable. You could then use that variable name to call the function too.
function someFunction(msg) {   alert(msg);}var showMsg = someFunction;//Either of these will workshowMsg('This is a test.'); ok, i understand what you mean.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...