javascript判断函数是否存在

写一个jquery插件,准备首先判断jquery是否安装,如果没安装就弹出提示。

假设funcName为函数名字,用如下方法就可以达到目标

一定要添加try catch块,否则不起作用。


try
{
    if(typeof($)=="function")
    {
        funcName();
    }
}catch(e)
{
    //alert("not function");
}


( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000355176{main}( ).../index.php:0
20.0001355464require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.168910158784require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.170110229928include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.251010786472get_template_part( ).../single.php:5
60.251010786992locate_template( ).../general-template.php:167
70.251010787088load_template( ).../template.php:643
80.251010787472require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.255810772584cwppos_show_review( ).../content-single.php:29

1 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注