concat1.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v); }
  6. Object.prototype.concat = Array.prototype.concat;
  7. var n = 10;
  8. var a = new Array();
  9. var o = new Object();
  10. for (var i=0; i<10; i++) {
  11. o[i] = a[i] = i * i + 1;
  12. }
  13. write(a.concat());
  14. write(o.concat());
  15. var x = a.concat(undefined) + "";
  16. write(x);
  17. write(a.concat(undefined));
  18. write(o.concat(undefined));
  19. write(a.concat(null));
  20. write(o.concat(null));
  21. write(a.concat("hello"));
  22. write(o.concat("hello"));
  23. write(a.concat(a));
  24. write(o.concat(a));
  25. write(a.concat(o));
  26. write(o.concat(o));
  27. var b = Array.prototype.concat.call(10);
  28. write(b[0] == 10); // true
  29. write(b[0] === 10); // false
  30. //implicit calls
  31. var a ;
  32. var arr = [10];
  33. Object.defineProperty(Array.prototype, "4", {configurable : true, get: function(){a = true; return 30;}});
  34. a = false;
  35. arr.length = 6;
  36. var f = arr.concat([30]);
  37. WScript.Echo(a);