Javascript prototypical inheritance made easy

Inheritance, multiple inheritance and mixins in 4 steps:
  1. Define function A filled with this.myProperties
  2. Define a function B you want to receive the properties
  3. FunctionA.call(FunctionB.prototype)
  4. myFunctionB = new FunctionB()
myFunctionB will have the properties defined in FunctionA.

This is easy to do, so you can design you own ways of sharing properties among functions. 


function UtilityBelt(){
   this.batBuckle=true // "this" is Batman during the "call"
   this.batarang=true
}
var Batman=function(){
}
var p=Batman.prototype //nothing to see here yet

var bruce=new Batman()

UtilityBelt.call(Batman.prototype) //inheritance!
Batman.prototype.holster=null
console.log(bruce.holster)//null
console.log (bruce.batBuckle)//true
bruce.batBuckle=false
console.log (bruce.batBuckle)//false
bruce.AGE=55
console.log (bruce.AGE)//55

var kate=new Batman()

Batman.prototype.holster=true
kate.AGE=44
console.log(kate.holster)//true
console.log(bruce.holster)//true (everybody has the same protoype utility belt)
console.log (bruce.AGE)//55 (everybody their own age)
console.log (kate.AGE)//44
If you add a property to the prototype ("Batman"), all the children get the same property.
If you add a property to an instance ("bruce"), each instance has its own property.