Home >Web Front-end >JS Tutorial >Javascript method to determine whether a function exists_javascript skills

Javascript method to determine whether a function exists_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:44:47929browse
Copy code The code is as follows:

window.onload=function(){
try{

if(test&&typeof(test)=="function"){
test();
}else{
alert("Function that does not exist");
}
}catch(e){
}
}
function test(){
alert("Function execution...");
}

If not If it exists, an exception will be thrown, so try...catch must be added.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn