Drycodez Posted August 11, 2011 Share Posted August 11, 2011 Its it possible to call a function without the brackets?e.g: var call=method; i have seen script like that, but i dont knw why! Link to comment Share on other sites More sharing options...
thescientist Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
ShadowMage Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
Drycodez Posted August 11, 2011 Author Share Posted August 11, 2011 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 More sharing options...
jeffman Posted August 11, 2011 Share Posted August 11, 2011 nm Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.