JS singleton inheritance
by Ben Clayton
HTML
Using jQuery extend to merge two json singletons (configs) together. Output in console.
JavaScript
var infx={}
infx.forms = {
name:'Bat',
price:{net:2,vatrate:'20%'},
show:function(){
console.log("product name is "+this.name+", price net "+this.price.net+ ", vat rate "+this.price.vatrate);
}
}
var luco={};
// add true for deep recursive to allow 'vatrate' to merge correctly
luco.forms = $.extend( true,{}, infx.forms, {
price:{net:4},
name:'Ball',
})
infx.forms.show();
luco.forms.show();