Skip to content

Instantly share code, notes, and snippets.

@blaja blaja/.js
Created Aug 8, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.