JS implements a simple instance of the library sharing metamodel
- 2020-07-21 06:31:49
- OfStack
An example of JS is presented in this paper. Share to everybody for everybody reference. The details are as follows:
<!DOCTYPE html>
<html>
<head>
<title> Enjoy member model </title>
</head>
<body>
<script>
/*
*flyweight Enjoy member model
*/
// Example is 1 Libraries keep and borrow books ->_->
var Book = function(id, title, author, genre, pageCount, publisherId, ISBN, checkoutDate, checkoutMember /* There are 1 some */){
this.id = id;
this.title = title;
this.author = author;
this.genre = this.genre;
this.pageCount = pageCount;
this.publisherId = publisherId;
this.ISBN = ISBN;
/*...*/
this.checkoutDate = checkoutDate;
this.checkoutMember = checkoutMember;
};
Book.prototype = {
getTitle : function(){
return this.title;
},
getAuthor : function(){
return this.author;
},
getISBN : function(){
return this.ISBN;
},
/*__more.._*/
updateCheckoutStatus : function(booId,checkoutDate,checkoutMember){
this.id = bookId;
this.checkoutDate = checkoutDate;
this.checkoutMember = checkoutMember;
/*_more.._*/
}
};
// The following is the version of sharing yuan; PS (using the 1 a OBJ Save books so you can have as many books as you want.
var BookFactory = (function(){
var existingBooks = {},existingBook;
return {
createBook : function(title,author,genre,ISBN){
existingBook = existingBooks[ISBN];
if(existingBook){
return existingBook;
}else{
var book = new Book(/*_moreData_bookInfo == _*/)
return existingBooks[ISBN] = book;
}
}
}
})();
var BookRecordManager = (function(){
var bookRecordDatabase = {};
return {
addBookRecord : function(id,ISNB/* == */){
var book = BookFactory.createBook(/**/);
bookRecordDatabase[id] = {
checkoutDate : checkoutDate,
checkoutMember : checkoutMember
};
},
updateCheckoutStatus : function(bookId,xx){
bookRecordDatabase[bookId] = {
xx : tt,
oo : yy
}
},
extend : function(){
/* Customize the various public methods */
}
}
})();
</script>
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.