-
-
Save blaja/af100b33d9b307e9e9bc to your computer and use it in GitHub Desktop.
Inspecting internal [[class]] of objects in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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