First, whether there is a specified function
Copy Code code as follows:
function Isexitsfunction (funcName) {
try {
if (typeof eval (funcName) = = "function") {
return true;
}
catch (e) {}
return false;
}
Second, similar to PHP commonly used to determine whether the existence of a function, does not exist to create
Copy Code code as follows:
if (typeof String.prototype.endsWith!= ' function ') {
String.prototype.endsWith = function (suffix) {
return this.indexof (suffix, this.length-suffix.length)!==-1;
};
}
Third, to determine whether the JS function exists, if the existence of the execution
Assuming that funcname is the function name, you can achieve the goal by using the following method
Be sure to add a try catch block, otherwise it will not work.
Copy Code code as follows:
Try
{
if (typeof eval (funcName) = = "function")
{
FuncName ();
}
}catch (e)
{
Alert ("not function");
}
Four, whether the existence of the specified variable
Copy Code code as follows:
function Isexitsvariable (variableName) {
try {
if (typeof (variableName) = = "undefined") {
Alert ("value is undefined");
return false;
} else {
Alert ("value is true");
return true;
}
catch (e) {}
return false;
}