| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 4 | <head> |
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> |
|---|
| 6 | |
|---|
| 7 | <!-- Provide a title. This will be shown on the generated chart --> |
|---|
| 8 | <title>Demo Test Suite</title> |
|---|
| 9 | |
|---|
| 10 | <script type="text/javascript" |
|---|
| 11 | src="http://www.broofa.com/Tools/JSLitmus/JSLitmus.js"></script> |
|---|
| 12 | <script type="text/javascript"> |
|---|
| 13 | |
|---|
| 14 | // Module pattern class definition. |
|---|
| 15 | var Book1 = function( newIsbn ) { |
|---|
| 16 | // Private attributes. |
|---|
| 17 | var isbn = newIsbn; |
|---|
| 18 | |
|---|
| 19 | // Privileged methods. |
|---|
| 20 | this.getIsbn = function() { |
|---|
| 21 | return isbn; |
|---|
| 22 | }; |
|---|
| 23 | this.setIsbn = function( newIsbn ) { |
|---|
| 24 | isbn = newIsbn; |
|---|
| 25 | }; |
|---|
| 26 | }; |
|---|
| 27 | |
|---|
| 28 | // Prototype pattern class definition. |
|---|
| 29 | var Book2 = function( isbn ) { // implements Publication |
|---|
| 30 | this._isbn = isbn; |
|---|
| 31 | } |
|---|
| 32 | Book2.prototype = { |
|---|
| 33 | getIsbn: function() { |
|---|
| 34 | return this._isbn; |
|---|
| 35 | }, |
|---|
| 36 | setIsbn: function( isbn ) { |
|---|
| 37 | this._isbn = isbn; |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | // Test create instance of class and accessing it's privileged functions. |
|---|
| 43 | JSLitmus.test('privilege based class ', function( count ) { |
|---|
| 44 | |
|---|
| 45 | while ( count-- ) |
|---|
| 46 | { |
|---|
| 47 | var book = new Book1('978-3-16-148410-1'); |
|---|
| 48 | book.setIsbn('978-3-16-148410-0'); |
|---|
| 49 | book.getIsbn(); |
|---|
| 50 | } |
|---|
| 51 | ; |
|---|
| 52 | }); |
|---|
| 53 | |
|---|
| 54 | // Test create instance of class and accessing it's prototype functions. |
|---|
| 55 | JSLitmus.test('prototype based class ', function( count ) { |
|---|
| 56 | |
|---|
| 57 | while ( count-- ) |
|---|
| 58 | { |
|---|
| 59 | var book = new Book2('978-3-16-148410-1'); |
|---|
| 60 | book.setIsbn('978-3-16-148410-0'); |
|---|
| 61 | book.getIsbn(); |
|---|
| 62 | } |
|---|
| 63 | ; |
|---|
| 64 | }); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | </script> |
|---|
| 68 | </head> |
|---|
| 69 | |
|---|
| 70 | <body> |
|---|
| 71 | </body> |
|---|
| 72 | </html> |
|---|