Take a real scenario With a javascript application to deal with transactions. We can design a general object called "transaction", as parent object Then design some other objects (invoice / stockreturn/ stockswap/stockadjust...), as child objects parent object var transaction={ createdon:XXX, createdby:"xxxx", totalamount:"xxx" cal_gst:function(rate){ this.totalamount*rate } }; Child object var invoice=inheritfrom(transaction) invoice.setinvoiceno=function(){ //some codes } Then the invoice object has all the members as transaction has. var stockreturn=inheritfrom(transaction) stockreturn.stock_reusable=false... Then the stockreturn object has all the members as transaction has. |