JavaScript Sprawdź, czy istnieje funkcja
//check if sayHello() function exists
if (typeof sayHello === "function") {
// This function exists
}
Grepper
//check if sayHello() function exists
if (typeof sayHello === "function") {
// This function exists
}
if (typeof yourFunctionName == 'function') {
yourFunctionName();
}
if (typeof payment === "function")
{
// Do something
}
if (typeof sourceObj.someMethod === "function") {
// you are safe using the method
sourceObj.someMethod();
}
How to check if function exists in JavaScript?