Skip to content

Instantly share code, notes, and snippets.

@yqt
Created October 9, 2013 01:52
Show Gist options
  • Select an option

  • Save yqt/6894910 to your computer and use it in GitHub Desktop.

Select an option

Save yqt/6894910 to your computer and use it in GitHub Desktop.
check the type of an object in js
function is(type, obj) {
var clas = Object.prototype.toString.call(obj).slice(8, -1);
return obj !== undefined && obj !== null && clas === type;
}
is('String', 'test'); // true
is('String', new String('test')); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment