Skip to content

Instantly share code, notes, and snippets.

@0x04
Last active May 3, 2020 00:07
Show Gist options
  • Save 0x04/e00c802a54118f827358 to your computer and use it in GitHub Desktop.
Save 0x04/e00c802a54118f827358 to your computer and use it in GitHub Desktop.
/**
* Returns the internal class name of the given object.
* @private
* @param {*} value
* @param {String} [compare]
* @returns {Boolean|String}
*/
function _is(value, compare)
{
var type = Object.prototype.toString.call(value);
// Extract the real data type e.g. "[object Object]"
// -----------------------------------------^^^^^^
type = type.substring(8, type.length - 1);
return (typeof compare == 'string')
? (compare.split(/[^$\w]/).indexOf(type) > -1)
: type;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment