Jump to content

method();


Drycodez
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...