Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // Currently...
  2. (function () {
  3. var forEach = (function () {
  4. var forEach;
  5. function Properties() {
  6. this.toString = 1;
  7. }
  8. Properties.prototype.toString = 1;
  9.  
  10. // Iterate over a new instance of `Properties` to detect `for...in` bugs.
  11.  
  12. if (!size) {
  13. // JScript fork.
  14. forEach = function forEach() {
  15. // ...
  16. };
  17. } else if (size == 2) {
  18. // Safari 2 fork.
  19. forEach = function forEach() {
  20. // ...
  21. }
  22. } else {
  23. // Normal environments.
  24. forEach = function forEach() {
  25. // ...
  26. };
  27. }
  28. return forEach;
  29. }());
  30. }());
  31.  
  32. // Possible Future Implementation...
  33. (function () {
  34. // Define the library methods without forking.
  35. var hasOwnProperty = {}.hasOwnProperty;
  36. function forEach(iterator, object) {
  37. // ...
  38. }
  39. function fold(iterator, memo, object) {
  40. // ...
  41. }
  42. function isPropertyOf(object, property) {
  43. // ...
  44. }
  45.  
  46. // Implement `hasOwnProperty` in Safari 2.
  47. if (typeof hasOwnProperty != 'function') {
  48. hasOwnProperty = function (property) {
  49. // ...
  50. };
  51. }
  52.  
  53. // Use defined library methods to detect `for...in` bugs in legacy engines.
  54. function Properties() {
  55. this.toString = 1;
  56. }
  57. Properties.prototype.toString = 1;
  58. if (fold(function (memo) {
  59. return ++memo;
  60. }, 0, new Properties) != 1) {
  61. // Wrap the `forEach` function in IE and Safari 2.
  62. }
  63. }());
Add Comment
Please, Sign In to add comment