Learning Object-oriented small examples of books, understanding object classes and object-oriented ideas.
Code
Function bookdata (BID, bname, bhasout, bprice) {// entity object
This. ID = bid;
This. Name = bname;
This. hasout = bhasout;
This. Price = bprice;
};
Libary = [
[1, "C # programming", 1,100], [2, "C standard library", 1,200], [3, "network programming", 1,200]
];
Libary. findbookbyid = function (ID ){
For (VAR I = 0; I <this. length; I ++ ){
If (libary [I] [0] = ID ){
If (libary [I] [2] = 0 ){
Alert ("This book has been borrowed .");
Return;
}
Libary [I] [2] = 0;
Alert ("successful borrowing ");
Return new bookdata (libary [I] [0], libary [I] [1], libary [I] [2], libary [I] [3]);
}
}
Return "notfind ";
};
Function book (ID ){
This. Data = libary. findbookbyid (ID );
If (this. Data = "notfind "){
Alert ("books not found ");
}
};
Book. Prototype. Return = function (){
For (VAR I = 0; I <libary. length; I ++ ){
If (libary [I] [0] = This. Data. ID ){
Libary [I] [2] = 1;
}
}
This. Data = undefined;
};
Book. Prototype. paybook = function (){
For (VAR I = 0; I <libary. length; I ++ ){
If (libary [I] [0] = This. Data. ID ){
Alert (libary [I] [3]);
}
}
};
Book. Prototype. reborrow = function (){
// Continue to borrow
};
Test code:
Code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
</Head>
<Body>
<SCRIPT src = "jscript. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT>
VaR B = New Book (2 );
B. Return ();
VaR BB = New Book (2 );
</SCRIPT>
</Body>
</Html>