Objects contain a hidden link property. This link points to the prototype member of the constructor of the object.
When items are accessed from an object by the dot notation or the subscript notation, if the item is not found in the object then the link object is examined[e81] . If it is not found in the link object, and if the link object itself has a link object, then that link object is examined. If the chain[e82] of link objects is exhausted, then undefined is returned.
This use of prototype link chains provides a sort of inheritance[e83] .
Members can be added to the prototype by assignment. Here we define a new class Demo, which inherits from class Ancestor, and adds its own method foo.
function Demo() {}
Demo.prototype = new Ancestor();
Demo.prototype.foo = function () {};
Vars
Named variables are defined with the var statement. When used inside of a function, var defines variables with function-scope. The vars are not accessible from outside of the function. There is no other granularity[e84] of scope in JavaScript. In particular, there is no block-scope.
Any variables used in a function which are not explicitly defined as var are assumed[e85] to belong[e86] to an outer scope, possibly to the Global Object.
Vars which are not explicitly initialized are given the value undefined.
Vars are not typed. A var can contain a reference to an object, or a string or a number or a boolean or null or undefined.
A new set of vars is made every time the function is called. This allows functions to be recursive.