Skip to content

Instantly share code, notes, and snippets.

@finalfantasia
Last active August 29, 2015 14:06
Show Gist options
  • Save finalfantasia/d95d2921578927496a13 to your computer and use it in GitHub Desktop.
Save finalfantasia/d95d2921578927496a13 to your computer and use it in GitHub Desktop.
Fun with JavaScript Prototypes
// Fun
Object instanceof Function // true
Function instanceof Object // true
// Types of various prototype objects:
typeof Object.prototype === 'object' // true
typeof Boolean.prototype === 'object' // true
typeof Number.prototype === 'object' // true
typeof String.prototype === 'object' // true
typeof Function.prototype === 'function' // true, see: http://ecma262-5.com/ELS5_HTML.htm#Section_15.3.4
Function.prototype instanceof Function // false
Function.prototype instanceof Object // true
// Other interesting stuff
Object.prototype is {/* object with built-in methods, e.g hasOwnProperty, toString, etc. */}
(Object.prototype).__proto__ === null // true, top of prototype chain
(Object.prototype).prototype === undefined // true, instances of Object have no 'prototype' property
Function.prototype is {/* function with built-in methods, e.g apply, call, etc. */}
(Function.prototype).__proto__ === Object.prototype // true, see: http://ecma262-5.com/ELS5_HTML.htm#Section_15.3.4
(Function.prototype).prototype === undefined // true, because: Function.prototype is an instance of Object
Object.__proto__ === Function.prototype // true, Object is a constructor (function) thus an instance of Function
Function.__proto__ === Function.prototype // true, Function is a constructor (function) thus an instance of Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment