[转]js 判断js函数、变量是否存在
本文转自:http://blog.csdn.net/liang4571231/article/details/4042519
在进行js编程时,总会出现可能一些函数或者变量未定义而被引用,导致报错的情况。为了避免此类事情的发生,可以在调用前判断函数是否已经被定义。
函数:
- try
- {
- if(typeof(eval(funcName))=="function")
- {
- funcName();
- }
- }catch(e)
- {
- alert("not function");
- }
变量:
- function check()
- {
- if (typeof(myvalue)=="undefined")
- {
- alert("value is undefined");
- }
- else
- {
- alert("value is true");
- }
- }
posted on 2013-10-07 10:05 freeliver54 阅读(8984) 评论(0) 编辑 收藏 举报