Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var $ = (function(){
- var obj = {};
- return obj;
- })();
- $.each = function(collection,fn){
- if(collection.constructor.name === 'Array'){
- for(var i = 0; i < collection.length; i++){
- fn.call(this,collection[i]);
- }
- }else{
- for(var prop in collection){
- fn.call(this,collection[prop]);
- }
- }
- };
- $.each([1,2,3,7,8],function(num){
- console.log(num * 2);
- });
- $.each(['A','B','C'],function(char){
- console.log(char);
- });
- 2
- 4
- 6
- 14
- 16
- A
- B
- C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement