yano3nora
7/1/2017 - 4:25 AM

[js: isTypeOf(type, data)] src = http://bonsaiden.github.io/JavaScript-Garden/ja/ #js

[js: isTypeOf(type, data)] src = http://bonsaiden.github.io/JavaScript-Garden/ja/ #js

/**
 * isTypeOf
 * @param string type (String, Number, Boolean, Date, Error, Array, Function, RegExp, Object)
 * @param mix    data 
 */
function isTypeOf(type, obj) {
  var clas = Object.prototype.toString.call(obj).slice(8, -1);
  return obj !== undefined && obj !== null && clas === type;
}

is('String', 'hoge'); // true
is('String', new String('hoge')); // true