Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. var $ = (function(){
  2. var obj = {};
  3. return obj;
  4. })();
  5.  
  6. $.each = function(collection,fn){
  7.  
  8. if(collection.constructor.name === 'Array'){
  9. for(var i = 0; i < collection.length; i++){
  10. fn.call(this,collection[i]);
  11. }
  12. }else{
  13. for(var prop in collection){
  14. fn.call(this,collection[prop]);
  15. }
  16. }
  17.  
  18.  
  19. };
  20.  
  21.  
  22. $.each([1,2,3,7,8],function(num){
  23. console.log(num * 2);
  24. });
  25.  
  26. $.each(['A','B','C'],function(char){
  27. console.log(char);
  28. });
  29.  
  30. 2
  31. 4
  32. 6
  33. 14
  34. 16
  35. A
  36. B
  37. C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement