How to judge whether there is a function in JavaScript
Today, the editor will share with you the relevant knowledge points about how to judge whether there is a function in JavaScript. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
The method of judging whether there is a function in JavaScript
Look at the code first.
_ window.onload=function () {
Try {
If (test&&typeof (test) = = "function") {
Test ()
}
Else {
Alert ("function that does not exist")
}
}
Catch (exception) {
Alert (exception)
}
}
Function test () {
Alert ("function execution …")
}
The first case is that the function does exist, then the function will be executed.
The second case is that the function does not exist, but if an object or variable with that name exists in this field, it is a function that indicates that it does not exist.
The third case is that the function does not exist, the object or variable does not exist, that is, the name is undefined, it will indicate that the function is not defined.
These are all the contents of the article "how to determine whether a function exists in JavaScript". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.