(简单)问题 - 函数调用没有() [英] (simple) question - function calls without ()

查看:62
本文介绍了(简单)问题 - 函数调用没有()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我几天前就记得这件事,并且正在寻找一个

的原因。我试图像这样调用一个函数:


addEvent(无论如何,无论如何,functionName());


我记得它不喜欢括号()。我摆脱了它们,

它起作用了。这背后的原因是什么?你什么时候?
应该添加()?


谢谢!


eddie

解决方案

ed在2007年6月17日上午10:15发表以下内容:

$ b $嗨那里,


我刚刚记得这几天,并且正在寻找一个理由

。我试图像这样调用一个函数:


addEvent(无论如何,无论如何,functionName());


我记得它不喜欢括号()。我摆脱了它们,

它起作用了。这背后的原因是什么?你什么时候?
应该添加()?



当你想要正确执行该函数时。或者,你是函数
调用期望()在那里。使用(),函数执行

然后上面的函数调用会结束,就像这样:

这样的东西:


addEvent(无论如何,returnFromfunctionName);


如果没有(),你只需传递一个函数的名称。


-

兰迪

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb写道:


ed在2007年6月17日上午10:15发表以下内容:


>你好,

我刚才记得这个,并且正在寻找一个
addEvent(无论如何,无论如何,functionName());

我记得它不喜欢括号( )。我摆脱了它们,
它起作用了。这背后的原因是什么?你什么时候应该添加()?



当你想要正确执行该功能时。


或者,你调用的函数需要()为那里。



我不明白这个,你能解释一下这个吗?或者

给我一个例子?


我不知道该函数将如何期待它会在那里,甚至可以告诉怎么样它被调用了。


使用(),函数执行

然后你上面的函数调用将会结束

这样的东西:


addEvent(无论如何,返回.FromfunctionName);


没有()你是只需传递一个函数的名称。



谢谢(提前)!


-

-Lost

删除要通过电子邮件回复的额外单词。不要给我发电子邮件。我是开玩笑的。不,我不是。


Randy Webb写道:


ed在6/17/2007上说了以下内容上午10:15:


>你好,

我刚刚记得这几天,并且正在寻找一个<它的原因。我试图像这样调用一个函数:

addEvent(无论如何,无论如何,functionName());

我记得它不喜欢括号( )。我摆脱了它们,
它起作用了。这背后的原因是什么?你什么时候应该添加()?



当你想要正确执行该功能时。或者,你是函数
调用期望()在那里。使用(),函数执行

然后上面的函数调用会结束,就像这样:

这样的东西:


addEvent(无论如何,returnFromfunctionName);


如果没有(),你只需传递一个函数的名称。



不是函数的名称,而是函数本身。


Hi there,

I just remembered this from a few days ago, and was looking for a
reason for it. I was trying to call a function as so:

addEvent( whatever, whatever, functionName() );

and as I recall it didn''t like the parenthesis (). I got rid of them,
and it worked. What is the reasoning behind this? When are you
supposed to add the () ?

Thanks!

eddie

解决方案

ed said the following on 6/17/2007 10:15 AM:

Hi there,

I just remembered this from a few days ago, and was looking for a reason
for it. I was trying to call a function as so:

addEvent( whatever, whatever, functionName() );

and as I recall it didn''t like the parenthesis (). I got rid of them,
and it worked. What is the reasoning behind this? When are you
supposed to add the () ?

When you want the function executed right then. Or, the function you are
calling expects the () to be there. With the (), the function executes
then and what your above function call would end up as would be
something like this:

addEvent( whatever, whatever, returnFromfunctionName );

Without the () you are simply passing the name of a function.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb wrote:

ed said the following on 6/17/2007 10:15 AM:

>Hi there,

I just remembered this from a few days ago, and was looking for a
reason for it. I was trying to call a function as so:

addEvent( whatever, whatever, functionName() );

and as I recall it didn''t like the parenthesis (). I got rid of them,
and it worked. What is the reasoning behind this? When are you
supposed to add the () ?


When you want the function executed right then.

Or, the function you are calling expects the () to be there.

I don''t understand this, could you explain this a little further? Or
give me an example?

I have no clue how the function would "expect" it to be there, or even
be able to tell "how" it was called.

With the (), the function executes
then and what your above function call would end up as would be
something like this:

addEvent( whatever, whatever, returnFromfunctionName );

Without the () you are simply passing the name of a function.

Thank you (in advance)!

--
-Lost
Remove the extra words to reply by e-mail. Don''t e-mail me. I am
kidding. No I am not.


Randy Webb wrote:

ed said the following on 6/17/2007 10:15 AM:

>Hi there,

I just remembered this from a few days ago, and was looking for a
reason for it. I was trying to call a function as so:

addEvent( whatever, whatever, functionName() );

and as I recall it didn''t like the parenthesis (). I got rid of them,
and it worked. What is the reasoning behind this? When are you
supposed to add the () ?


When you want the function executed right then. Or, the function you are
calling expects the () to be there. With the (), the function executes
then and what your above function call would end up as would be
something like this:

addEvent( whatever, whatever, returnFromfunctionName );

Without the () you are simply passing the name of a function.

Not the name of the function, but the function itself.


这篇关于(简单)问题 - 函数调用没有()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆