Skip to content

Instantly share code, notes, and snippets.

@adam-lynch
Created March 26, 2014 17:19
Show Gist options
  • Select an option

  • Save adam-lynch/9788513 to your computer and use it in GitHub Desktop.

Select an option

Save adam-lynch/9788513 to your computer and use it in GitHub Desktop.
# thing - {mixed}. Anything you want to get the type of.
getType: do =>
unless @classToType?
@classToType = {}
for type in ['Boolean', 'Number', 'String', 'Function', 'Array', 'Date', 'RegExp', 'Undefined', 'Null']
@classToType["[object #{type}]"] = type
return (thing) =>
className = Object::toString.call thing
return if @classToType[className]? then @classToType[className].toLowerCase() else 'object'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment