Search code examples
jqueryrubyjquery-steps

Is there a send method in JavaScript the way there is in Ruby to help DRY this up?


I am using the jquery-steps plugin and would like to call the steps initialization method on another form but with the same settings.

Is there a way to tell JavaScript to do this without having to call steps again with the same settings? I'm thinking of something analogous to the send method in Ruby if that helps.

Source code:

var formWizard = $('form#myform').children('div.page-1');
formWizard.steps({
    headerTag: "h3",
       bodyTag: "section"
    //other settings that make this steps method long
});

I want to use a send method like Ruby or some other way to avoid repeating the steps call with all the arguments:

var formWizard2 = $('form#myform').children('div.page-2');
var hash_args = {
    headerTag: "h3",
       bodyTag: "section"
    //other settings that make this steps method long
}
formWizard2.send(:steps, hash_args)

Solution

  • I might be misunderstanding your question... but why don't you just save the config to a variable and use it:

    var config = {
            headerTag: "h3",
            bodyTag: "section"
            //other settings that make this steps method long
    }
    
    formWizard.steps(config);
    var formWizard2 = $('form#myform').children('div.page-2');
    formWizard2.send(config)