Advertisement
Guest User

Untitled

a guest
Dec 25th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. [].forEach.call( document.querySelectorAll(sel), function(el) {
  2. });
  3.  
  4. NodeList.prototype.forEach = Array.prototype.forEach;
  5.  
  6. NodeList.prototype.forEach = HTMLCollection.prototype.forEach = Array.prototype.forEach;
  7.  
  8. NodeList.prototype.forEach = HTMLCollection.prototype.forEach = Array.prototype.forEach;
  9. NodeList.prototype.map = HTMLCollection.prototype.map = Array.prototype.map;
  10. NodeList.prototype.filter = HTMLCollection.prototype.filter = Array.prototype.filter;
  11. NodeList.prototype.reduce = HTMLCollection.prototype.reduce = Array.prototype.reduce;
  12. NodeList.prototype.reduceRight = HTMLCollection.prototype.reduceRight = Array.prototype.reduceRight;
  13. NodeList.prototype.every = HTMLCollection.prototype.every = Array.prototype.every;
  14. NodeList.prototype.some = HTMLCollection.prototype.some = Array.prototype.some;
  15.  
  16. ['forEach', 'map', 'filter', 'reduce', 'reduceRight', 'every', 'some'].forEach(
  17. function(p) {
  18. NodeList.prototype[p] = HTMLCollection.prototype[p] = Array.prototype[p];
  19. });
  20.  
  21. function forEach( a, fn ) {
  22. return [].forEach.call(a, fn);
  23. };
  24.  
  25. forEach(document.querySelectorAll(sel), function(el) {
  26. });
  27.  
  28. function map( a, fn ) {
  29. return [].map.call(a, fn);
  30. };
  31. function filter( a, fn ) {
  32. return [].filter.call(a, fn);
  33. };
  34. function reduce( a, fn ) {
  35. return [].reduce.call(a, fn);
  36. };
  37. function reduceRight( a, fn ) {
  38. return [].reduceRight.call(a, fn);
  39. };
  40. function every( a, fn ) {
  41. return [].every.call(a, fn);
  42. };
  43. function some( a, fn ) {
  44. return [].some.call(a, fn);
  45. };
  46.  
  47. [].slice.call(a)
  48.  
  49. function forEach(a, fn) {
  50. return [].forEach.call([].slice.call(a), fn);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement