array.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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] = RTLMakeArray.apply(this, forward);
  18. return result;
  19. },
  20. extend: function extend(methods){
  21. methods.__proto__ = this.prototype; // make instanceof work
  22. // to see constructor name in diagnostic
  23. var result = methods.init;
  24. methods.constructor = result.prototype.constructor;
  25. result.prototype = methods;
  26. result.extend = extend;
  27. return result;
  28. },
  29. copy: function (from, to){
  30. for(var prop in from){
  31. var v = from[prop];
  32. if (typeof v == "object")
  33. this.copy(v, to[prop]);
  34. else if (typeof v != "function")
  35. to[prop] = v;
  36. }
  37. }
  38. };
  39. var m = function (){
  40. var arraySize = 10;
  41. var a1 = RTL$.makeArray(10, 0);var a11 = RTL$.makeArray(10, 0);
  42. var a2 = RTL$.makeArray(5, function(){return RTL$.makeArray(10, 0);});
  43. var a3 = RTL$.makeArray(5, false);
  44. var a4 = RTL$.makeArray(3, 4, false);
  45. var anonymous$1 = RTL$.extend({
  46. init: function anonymous$1(){
  47. }
  48. });
  49. var a5 = RTL$.makeArray(3, function(){return new anonymous$1();});
  50. function p(){
  51. var a3 = RTL$.makeArray(1, 0);
  52. a3[0] = 1;
  53. }
  54. a1[0] = 1;
  55. a3[1] = true;
  56. a4[1][2] = true;
  57. a4[1][2] = true;
  58. RTL$.copy(a11, a1);
  59. }();