js实现一个简单的库订阅模型示例

本文用js描述了一个简单的图书馆收藏模式,供大家参考:





享受模式



*
*轻量级的享受方式
* /
/ /的例子是一个图书馆的图书借阅-> _ ->
VAR的书=功能(ID、标题、作者、体裁、总页数,publisherid,书号,checkoutdate,checkoutmember和一些{ / * * /)
this.id = ID;
this.title =标题;
this.author =作者;
this.genre = this.genre;
this.pagecount =总页数;
this.publisherid = publisherid;
this.isbn =书号;
**…
this.checkoutdate = checkoutdate;
this.checkoutmember = checkoutmember;
};
book.prototype = { {
GetTitle:函数(){
返回this.title;
},
getauthor:函数(){
返回this.author;
},
GetISBN:函数(){
返回this.isbn;
},
/ * * / _ __more ..
updatecheckoutstatus:功能(booid,checkoutdate,checkoutmember){
bookid this.id =;
this.checkoutdate = checkoutdate;
this.checkoutmember = checkoutmember;
/ * * / _ _more ..
}
};
轻量级版本/;PS(使用对象的书,这样你就可以节省很多的书)
Var BookFactory =(函数(){()
无功existingbooks = { },existingbook;
返回{
CreateBook:(标题、作者、体裁功能,ISBN){
existingbook = existingbooks ISBN } {;
如果(existingbook){
返回existingbook;
其他{ }
Var Book New书( / * _moredata_bookinfo = _ * /)
返回existingbooks { } =书ISBN;
}
}
}
})();
无功bookrecordmanager =(函数(){()
无功bookrecorddatabase = { };
返回{
addbookrecord:功能(ID,isnb / * = = { *)
VAR的书= bookfactory.createbook(* /);
bookrecorddatabase {id} = { {
checkoutdate:checkoutdate,
checkoutmember:checkoutmember
};
},
updatecheckoutstatus:功能(bookid,XX){
bookrecorddatabase bookid } = { { {
XX,
面向对象:YY
}
},
扩展:函数(){
所有公共方法都是定制的。
}
}
});







希望本文能对大家的javascript程序设计有所帮助。