|
此文章由 典 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 典 所有!转贴必须注明作者、出处和本声明,并保持内容完整
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. |
评分
-
参与人数 1 | 积分 +3 |
收起
理由
|
乱码
| + 3 |
Douglas crockford rules !! |
查看全部评分
|