JavaScript Utils

2019-04-02  本文已影响0人  yingjieg

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);
}
上一篇下一篇

猜你喜欢

热点阅读