for-each.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. var ArrayIterator = require("es6-iterator/array")
  3. , slice = Array.prototype.slice;
  4. module.exports = function (t, a) {
  5. var i = 0, x = ["raz", "dwa", "trzy"], y = {};
  6. t(
  7. x,
  8. function () {
  9. a.deep(slice.call(arguments, 0, 1), [x[i]], "Array " + i + "#");
  10. a(this, y, "Array: context: " + i++ + "#");
  11. },
  12. y
  13. );
  14. i = 0;
  15. t(
  16. (function () { return arguments; })("raz", "dwa", "trzy"),
  17. function () {
  18. a.deep(slice.call(arguments, 0, 1), [x[i]], "Arguments" + i + "#");
  19. a(this, y, "Arguments: context: " + i++ + "#");
  20. },
  21. y
  22. );
  23. i = 0;
  24. t(
  25. { 0: "raz", 1: "dwa", 2: "trzy", length: 3 },
  26. function () {
  27. a.deep(slice.call(arguments, 0, 1), [x[i]], "Array-like" + i + "#");
  28. a(this, y, "Array-like: context: " + i++ + "#");
  29. },
  30. y
  31. );
  32. i = 0;
  33. t(
  34. (x = "foo"),
  35. function () {
  36. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  37. a(this, y, "Regular String: context: " + i++ + "#");
  38. },
  39. y
  40. );
  41. i = 0;
  42. x = ["r", "💩", "z"];
  43. t(
  44. "r💩z",
  45. function () {
  46. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  47. a(this, y, "Unicode String: context: " + i++ + "#");
  48. },
  49. y
  50. );
  51. i = 0;
  52. t(
  53. new ArrayIterator(x),
  54. function () {
  55. a.deep(slice.call(arguments, 0, 1), [x[i]], "Iterator " + i + "#");
  56. a(this, y, "Iterator: context: " + i++ + "#");
  57. },
  58. y
  59. );
  60. };