Skip to content

Instantly share code, notes, and snippets.

@blaja
Created August 8, 2015 13:41
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 blaja/af100b33d9b307e9e9bc to your computer and use it in GitHub Desktop.
Save blaja/af100b33d9b307e9e9bc to your computer and use it in GitHub Desktop.
Inspecting internal [[class]] of objects in JS
// NOTE: this is specification dependent classification. It has nothing to do with formal class programming concept.
// The value of the [[Class]] internal property is defined by specification for every kind of built-in object.
// The value of the [[Class]] internal property of a host object may be any String value except one of:
// "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String".
// The value of a [[Class]] internal property is used internally to distinguish different kinds of objects.
Object.prototype.toString.call({}); // "[object Object]"
Object.prototype.toString.call([]); // "[object Array]"
Object.prototype.toString.call(function(){}); // "[object Function]"
Object.prototype.toString.call(''); // "[object String]"
Object.prototype.toString.call(0); // "[object Number]"
Object.prototype.toString.call(true); // "[object Boolean]"
Object.prototype.toString.call(/''/); // "[object RegExp]"
Object.prototype.toString.call(new Date); // "[object Date]"
Object.prototype.toString.call(new Error); // "[object Error]"
Object.prototype.toString.call(Math); // "[object Math]"
Object.prototype.toString.call(JSON); // "[object JSON]"
Object.prototype.toString.call(function(){return arguments;}()); // "[object Arguments]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment