检查功能是否存在 [英] Check if function exists

查看:86
本文介绍了检查功能是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看我页面上的任何脚本中是否存在某个功能?

我更喜欢它是否适用于Javascript和& VBScript。

How can I check if a function exists in any of the scripts on my page?
I prefer if it can work for both Javascript & VBScript.

推荐答案

CWaldman写道:
CWaldman wrote:
如何查看任何一个函数是否存在我的页面上的脚本?
我更喜欢它是否适用于Javascript和... VBScript。
How can I check if a function exists in any of the scripts on my page?
I prefer if it can work for both Javascript & VBScript.




我不知道VBscript。对于JavaScript,在绝大多数

的情况下:


if(myFunctionName){

//使用myFunctionName

}

就可以了。但是,如果''myFunctionName''有可能已声明或转换为某种类型而不是函数(比如

数字,字符串或数组) ,那么你可以使用(在Firefox中轻轻测试
和IE):


if(myFunctionName&& Function == myFunctionName.constructor){

//使用myFunctionName

}

避免使用try..catch,它通常被认为是最后的手段。

-

Rob



I have no idea about VBscript. For JavaScript, in the vast majority of
cases:

if (myFunctionName) {
// use myFunctionName
}
will do the trick. However, if it''s possible that ''myFunctionName'' has
been declared or converted to some type other than a Function (say
Number, String or Array), then you might use (lightly tested in Firefox
and IE):

if (myFunctionName && Function == myFunctionName.constructor) {
// use myFunctionName
}
Avoid using try..catch, it''s generally considered a last resort.
--
Rob


或者


if(typeof myFunctionName ==" ;功能)

{


}

Or perhaps

if (typeof myFunctionName=="function")
{

}


Baconbutty说以下内容10/19/2005 7:13 AM:
Baconbutty said the following on 10/19/2005 7:13 AM:
或者




或者你可能学会引用你所回复的内容?这不是很难。


请引用你要回复的内容。


如果你想要通过groups.google.com发布跟进,请勿使用

回复链接在文章的底部。点击显示选项在

文章的顶部,然后点击回复。在

文章标题的底部。


-

Randy

comp.lang .javascript常见问题解答 - http://jibbering.com/faq &新闻组周刊



Or perhaps you learn to quote what you are replying to? It is not that
difficult.

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don''t use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


这篇关于检查功能是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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