array.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 to){
  31. if (to.hasOwnProperty(prop)){
  32. var v = from[prop];
  33. if (v !== null && typeof v == "object")
  34. this.copy(v, to[prop]);
  35. else
  36. to[prop] = v;
  37. }
  38. }
  39. }
  40. };
  41. var m = function (){
  42. var arraySize = 10;
  43. var a1 = RTL$.makeArray(10, 0);var a11 = RTL$.makeArray(10, 0);
  44. var a2 = RTL$.makeArray(5, function(){return RTL$.makeArray(10, 0);});
  45. var a3 = RTL$.makeArray(5, false);
  46. var a4 = RTL$.makeArray(3, 4, false);
  47. var anonymous$1 = RTL$.extend({
  48. init: function anonymous$1(){
  49. }
  50. });
  51. var a5 = RTL$.makeArray(3, function(){return new anonymous$1();});
  52. function p(){
  53. var a3 = RTL$.makeArray(1, 0);
  54. a3[0] = 1;
  55. }
  56. a1[0] = 1;
  57. a3[1] = true;
  58. a4[1][2] = true;
  59. a4[1][2] = true;
  60. RTL$.copy(a11, a1);
  61. }();