Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Created July 1, 2017 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yano3nora/a806be5e065c62ae1873221877955fbd to your computer and use it in GitHub Desktop.
Save yano3nora/a806be5e065c62ae1873221877955fbd to your computer and use it in GitHub Desktop.
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment