Created
July 1, 2017 04:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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