Guest User

Untitled

a guest
Jul 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  4. <script type="text/javascript" src="test.js"></script>
  5. <script type="text/javascript">
  6. debugger;
  7.  
  8. // Do this because a page resart seems to keep old data
  9. function SetGlobals()
  10. {
  11. var ui;
  12. var el;
  13.  
  14. // Arr00
  15. ui = document.getElementById("Arr00");
  16. el = arr0.arrayGet(0);
  17. ui.innerHTML = el.m_String;
  18.  
  19. // Arr01
  20. ui = document.getElementById("Arr01");
  21. el = arr0.arrayGet(1);
  22. ui.innerHTML = el.m_String;
  23.  
  24. // Arr10
  25. ui = document.getElementById("Arr10");
  26. el = arr1.arrayGet(0);
  27. ui.innerHTML = el.m_String;
  28.  
  29. // Arr11
  30. ui = document.getElementById("Arr11");
  31. el = arr1.arrayGet(1);
  32. ui.innerHTML = el.m_String;
  33. }
  34.  
  35. function MyOnLoad()
  36. {
  37. SetGlobals();
  38. }
  39. </script>
  40. </head>
  41. <body onload="MyOnLoad()" style="width:100%; height: 100%; padding: 0 0 0 0; margin: 0 0 0 0; overflow: hidden; background:#000000">
  42.  
  43. <div id="divScreen" style="display: block; width:100%; height="100%">
  44. <div id="divMenu" style='float: left; background:#00FF00; border-color: #000000; border-width: 1px;'>
  45. <table>
  46. <tr>
  47. <td>
  48. Array 0/String 0: <label id="Arr00"></label>
  49. </td>
  50. </tr>
  51. <tr>
  52. <td>
  53. Array 0/String 1: <label id="Arr01"></label>
  54. </td>
  55. </tr>
  56. <tr>
  57. <td>
  58. Array 1/String 0: <label id="Arr10"></label>
  59. </td>
  60. </tr>
  61. <tr>
  62. <td>
  63. Array 1/String 1: <label id="Arr11"></label>
  64. </td>
  65. </tr>
  66. </table>
  67. </div>
  68. <div id="divMain" style='height: 100%; background:#0000FF; margin-left: 250px; border-color: #000000; border-width: 1px;'>
  69. </div>
  70. </div>
  71. </body>
  72. </html>
  73.  
  74. var BaseARR = function()
  75. {
  76. _arr = []; // new Array();
  77.  
  78. // Public functions that can access private members
  79. this.Add = function(arg)
  80. {
  81. var i, addAt;
  82.  
  83. if(arg==null || (addAt = FindEnterPos(arg))<0)
  84. return false;
  85.  
  86. // since adding and not deleting anything, nothing of value will be returned
  87. _arr.splice(addAt, 0, arg);
  88.  
  89. return true;
  90. };
  91. // This finds the entry position for in
  92. FindEnterPos = function(arg)
  93. {
  94. return (_arr.length + 1);
  95. };
  96. this.arrayGet = function(i)
  97. {
  98. return ((_arr != null && i >= 0 && i < _arr.length) ? _arr[i] : null);
  99. };
  100. };
  101.  
  102. var stringId = function(id, str)
  103. {
  104. // public has a this. , privates have just var
  105. this.m_Id = id; // int
  106. this.m_String = str; // string
  107. };
  108.  
  109. // This so allow statics
  110. var stringIdARR = function()
  111. {
  112. BaseARR.call(this);
  113. };
  114.  
  115. // using "braces on same line" style
  116. (function () {
  117. return {
  118. key: 'value'
  119. };
  120. })();
  121.  
  122. // using "braces on line by themself"-style
  123. (function ()
  124. {
  125. return
  126. {
  127. key: 'value'
  128. }
  129. })();
  130.  
  131. var anObject = {
  132. key: 'value'
  133. };
  134. function MakeAnObject() {
  135. }
  136.  
  137. MakeAnObject.prototype = anObject;
  138.  
  139. var o = new MakeAnObject();
  140.  
  141. console.log(o.key); // will output 'value'
  142.  
  143. function MakeThing() {
  144. }
  145.  
  146. MakeThing.prototype = {
  147. key: 'value'
  148. };
  149.  
  150. var o1 = new MakeThing(), o2 = new MakeThing();
  151.  
  152. console.log(o1); // will output 'value'
  153. console.log(o2); // will output 'value'
  154.  
  155. o2.key = 'other';
  156.  
  157. console.log(o1); // will output 'value'
  158. console.log(o2); // will output 'other'
  159.  
  160. MakeThing.prototype.key = 'changed';
  161.  
  162. console.log(o1); // will output 'changed'
  163. console.log(o2); // will output 'other'
  164.  
  165. delete o2.key;
  166.  
  167. console.log(o1); // will output 'changed'
  168. console.log(o2); // will output 'changed'
  169.  
  170. function BaseAAR {
  171. this._arr = []; // note >this<. You created a global array in your code.
  172. };
  173.  
  174. BaseAAR.prototype.add = function(arg) {
  175. var i, addAt;
  176.  
  177. // always use identity (triple) operators when comparing to null!
  178. if (arg === null || (addAt = this.findEnterPos(arg))<0)
  179. return false;
  180.  
  181. // since adding and not deleting anything, nothing of value will be returned
  182. this._arr.splice(addAt, 0, arg);
  183. return true;
  184. };
  185. // This finds the entry position for in
  186. BaseAAR.prototype.findEnterPos = function(arg) {
  187. return (_arr.length + 1);
  188. };
  189. BaseAAR.prototype.arrayGet = function(i) {
  190. return ((this._arr !== null && i >= 0 && i < this._arr.length) ? _arr[i] : null);
  191. };
  192.  
  193.  
  194. function StringIdAAR(id, str) {
  195. BaseAAR.call(this); // invoke the constructor of the base object
  196. this.m_Id = id; // int
  197. this.m_String = str; // string
  198. }
  199.  
  200. StringIdAAR.prototype = BaseAAR.prototype; // innherit from StringIdAAR prototype
Add Comment
Please, Sign In to add comment