2
0

array.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var RTL$ = {
  2. makeArray: function (/*dimensions, initializer*/){
  3. var forward = Array.prototype.slice.call(arguments);
  4. var result = new Array(forward.shift());
  5. var i;
  6. if (forward.length == 1){
  7. var init = forward[0];
  8. if (typeof init == "function")
  9. for(i = 0; i < result.length; ++i)
  10. result[i] = init();
  11. else
  12. for(i = 0; i < result.length; ++i)
  13. result[i] = init;
  14. }
  15. else
  16. for(i = 0; i < result.length; ++i)
  17. result[i] = this.makeArray.apply(this, forward);
  18. return result;
  19. },
  20. extend: function extend(methods){
  21. function Type(){
  22. for(var m in methods)
  23. this[m] = methods[m];
  24. }
  25. Type.prototype = this.prototype;
  26. var result = methods.init;
  27. result.prototype = new Type(); // inherit this.prototype
  28. result.prototype.constructor = result; // to see constructor name in diagnostic
  29. result.extend = extend;
  30. return result;
  31. },
  32. copy: function (from, to){
  33. for(var prop in to){
  34. if (to.hasOwnProperty(prop)){
  35. var v = from[prop];
  36. if (v !== null && typeof v == "object")
  37. this.copy(v, to[prop]);
  38. else
  39. to[prop] = v;
  40. }
  41. }
  42. }
  43. };
  44. var m = function (){
  45. var arraySize = 10;
  46. var a1 = RTL$.makeArray(10, 0);var a11 = RTL$.makeArray(10, 0);
  47. var a2 = RTL$.makeArray(5, function(){return RTL$.makeArray(10, 0);});
  48. var a3 = RTL$.makeArray(5, false);
  49. var a4 = RTL$.makeArray(3, 4, false);
  50. var anonymous$1 = RTL$.extend({
  51. init: function anonymous$1(){
  52. }
  53. });
  54. var a5 = RTL$.makeArray(3, function(){return new anonymous$1();});
  55. function p(){
  56. var a3 = RTL$.makeArray(1, 0);
  57. a3[0] = 1;
  58. }
  59. function p1(a/*ARRAY 10 OF INTEGER*/){
  60. }
  61. function p2(a/*VAR ARRAY 10 OF INTEGER*/){
  62. p1(a);
  63. }
  64. a1[0] = 1;
  65. a3[1] = true;
  66. a4[1][2] = true;
  67. a4[1][2] = true;
  68. p1(a1);
  69. p2(a1);
  70. RTL$.copy(a11, a1);
  71. }();