Skip to main content
added 8 characters in body; edited title
Source Link
konijn
  • 33.8k
  • 5
  • 69
  • 264

creating Creating a webtrend function to remove duplication using js apply and call

How can I re-factoringfactor the code forto remove duplication and extract intocreate a common method. ?

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use commonlogs.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

creating a webtrend function to remove duplication using js apply and call

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use commonlogs.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

Creating a webtrend function to remove duplication using js apply and call

How can I re-factor the code to remove duplication and create a common method ?

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use commonlogs.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

added 4 characters in body
Source Link
paul
  • 111
  • 2

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use commoncommonlogs.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use common.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use commonlogs.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

added 1209 characters in body
Source Link
paul
  • 111
  • 2

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

please refer to to :I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

http://stackoverflow.com/questions/8740634/creating-a-webtrend-function-to-remove-duplication-using-js-apply-and-call/8741082#8741082 i can use common.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

thanksThanks for any help /suggestionsadvice or suggestions.

re-factoring the code for duplication and extract into a common method.

please refer to to :

http://stackoverflow.com/questions/8740634/creating-a-webtrend-function-to-remove-duplication-using-js-apply-and-call/8741082#8741082

thanks for any help /suggestions

re-factoring the code for duplication and extract into a common method.

(function(){
    
    $("#a", "#main").bind("mouseover", function(){
              var id1 = $("#one").text(),
                  args = ["DCSext.common1","common1","DCSext.common2","DCSext.title","one", "DCSext.ti", id1];
                  
              dcsMultitrack.apply(this, args);
     });
    
    $("#b", "#cool").bind("click", function(){
           var id2 = $("#two").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.title", "two", "DCSext.some", id2];
               dcsMultitrack.apply(this, args);
    });
    
    $("body").delegate("a", "click", function(){
         var id3 = $("#three").text(),
               args = ["DCSext.common1","common1","DCSext.common2","DCSext.new", "what", "DCSext.where", "us"];
               dcsMultitrack.apply(this, args);
    });
    
    }());

I have some common logs which are almost repeated in all callbacks. I can use a variable like

var commonlogs = ["DCSext.common1","common1","DCSext.common2","common2", "DCSext.common3", "common3" ];

i can use common.push("DCSext.title","one","DCSext.ti", "two"). But not finding a proper way to re-factoring repeating the DCSext stuff again and again since its very granular level .

Thanks for any advice or suggestions.

Source Link
paul
  • 111
  • 2
Loading