for-each.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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(x, function () {
  7. a.deep(slice.call(arguments, 0, 1), [x[i]], "Array " + i + "#");
  8. a(this, y, "Array: context: " + i++ + "#");
  9. }, y);
  10. i = 0;
  11. t((function () {
  12. return arguments;
  13. }("raz", "dwa", "trzy")), function () {
  14. a.deep(slice.call(arguments, 0, 1), [x[i]], "Arguments" + i + "#");
  15. a(this, y, "Arguments: context: " + i++ + "#");
  16. }, y);
  17. i = 0;
  18. t({ 0: "raz", 1: "dwa", 2: "trzy", length: 3 }, function () {
  19. a.deep(slice.call(arguments, 0, 1), [x[i]], "Array-like" + i + "#");
  20. a(this, y, "Array-like: context: " + i++ + "#");
  21. }, y);
  22. i = 0;
  23. t(x = "foo", function () {
  24. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  25. a(this, y, "Regular String: context: " + i++ + "#");
  26. }, y);
  27. i = 0;
  28. x = ["r", "💩", "z"];
  29. t("r💩z", function () {
  30. a.deep(slice.call(arguments, 0, 1), [x[i]], "String " + i + "#");
  31. a(this, y, "Unicode String: context: " + i++ + "#");
  32. }, y);
  33. i = 0;
  34. t(new ArrayIterator(x), function () {
  35. a.deep(slice.call(arguments, 0, 1), [x[i]], "Iterator " + i + "#");
  36. a(this, y, "Iterator: context: " + i++ + "#");
  37. }, y);
  38. };