美文网首页
JavaScript Utils

JavaScript Utils

作者: yingjieg | 来源:发表于2019-04-02 14:36 被阅读0次

Check variable is object or function

function objectOrFunction(x) {
  let type = typeof x;
  return x !== null && (type === 'object' || type === 'function');
}

Check vairable is function

function isFunc() {
  return typeof x === 'function';
}

Check variable is array

function isArray(value) {
  let _isArray;
  if (Array.isArray) {
    _isArray = Array.isArray;
  } else {
    _isArray = x => Object.prototype.toString.call(x) === '[object Array]';
  }

  _isArray(value);
}

相关文章

网友评论

      本文标题:JavaScript Utils

      本文链接:https://www.haomeiwen.com/subject/bvwwbqtx.html