Foo() would set x's prototype to Foo.prototype, // and Foo.prototype has a constructor slot pointing back to Foo). x = new Foo(); // The above is almost equivalent to y = {}; y.constructor = Foo; y.constructor(); // Except x.constructor == y.constructor // true x instanceof Foo // true y instanceof Foo // false // y's prototype is Object.prototype, not // Foo.prototype, since it was initialised with // {} instead of new Foo. // Even though Foo is set to y's constructor slot, // this is ignored by instanceof - only y's prototype's // constructor slot is considered. Functions are objects themselves, which can be used to produce an effect similar to "static properties" (using C++/Java terminology) as shown below. (The function object also has a special prototype property, as discussed in the "Inheritance" section below.) Object deletion is rarely used as the scripting engine will garbage collect objects that are no longer being referenced. Inheritance JavaScript supports inheritance hierarchies through prototyping in the manner of Self. In the following example, the class inherits from the class. When is created as , the reference to the base instance of is copied to . Derive does not contain a value for , so it is retrieved from when is accessed. This is made clear by changing the value of , which is reflected in the value of . Some implementations allow the prototype to be accessed or set explicitly using the slot as shown below. function Base() { this.anOverride = function() { console.log("Base::anOverride()"); }; this.aBaseFunction = function() { console.log("Base::aBaseFunction()"); }; } function Derived() { this.anOverride = function() { console.log("Derived::anOverride()"); }; } base = new Base(); Derived.prototype = base; // Must be before new Derived() Derived.prototype.constructor = Derived; // Required to make `instanceof` work d = new Derived(); // Copies Derived.prototype to d instance's hidden prototype slot. d instanceof Derived; // true d instanceof Base; // true base.aBaseFunction = function() { console.log("Base::aNEWBaseFunction()"); } d.anOverride(); // Derived::anOverride() d.aBaseFunction(); // Base::aNEWBaseFunction() console.log(d.aBaseFunction == Derived.prototype.aBaseFunction); // true console.log(d.__proto__ == base); // true in Mozilla-based implementations and false in many others. The following shows clearly how references to prototypes are copied on instance creation, but that changes to a prototype can affect all instances that refer to it. function m1() { return "One"; } function m2() { return "Two"; } function m3() { return "Three"; } function Base() {} Base.prototype.m = m2; bar = new Base(); console.log("bar.m