This article example tells the code for js to determine whether a method exists. Share it for your reference.
The specific code is as follows:
Copy the code as follows: <html>
<head>
<title> js determines whether a method exists</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
window.onload = function(){
try{
if(test && typeof(test) == "function"){
test();
}
}catch(e){
alert("Method does not exist");
}
}
function test(){
alert("I am the test() method");
}
</script>
</head>
<body>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.