- Define function A filled with this.myProperties
- Define a function B you want to receive the properties
- FunctionA.call(FunctionB.prototype)
- 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 an instance ("bruce"), each instance has its own property.