JavaScript中判断函数、变量是否存在

转载:http://www.jb51.net/article/67551.htm

 

一、是否存在指定函数

 

function isExitsFunction(funcName) {
  try {
    if (typeof(eval(funcName)) == "function") {
      return true;
    }
  } catch(e) {}
  return false;
}

 

 二、判断是否存在变量

 

function isExitsVariable(variableName) {
  try {
    if (typeof(eval(variableName)) == "undefined") {
      //alert("value is undefined"); 
      return false;
    } else {
      //alert("value is true"); 
      return true;
    }
  } catch(e) {}
  return false;
}

 

posted @ 2018-01-24 13:25  柒月风华  阅读(178)  评论(0编辑  收藏  举报