1
0

for-each.js 1.3 KB

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