How to initialiaze an object and assign different variables javascript

I have created an object where i need to assign some variables(parameters) and when the object is called, the variables(parameters) change. Here is my code:

var Modal = {

    init: function () {

        contact1: "";
        contact2: "";
        aboutus1: "";
        aboutus2: "";
        privacy1: "";
        privacy2: "";
        terms1:   "";
        terms2:   "";

        $(".modaltrigger").removeAttr("target");

        $(".modaltrigger").click(function () {

            if ($(this).is("#contact")) {

                $('#primary_url').attr('href', contact1);
                $('#secondary_url').attr('href', contact2);

            } else if ($(this).is("#aboutus")) {

                $('#primary_url').attr('href', aboutus1);
                $('#secondary_url').attr('href', aboutus2);

            } else if ($(this).is("#termsconditions")) {

                $('#primary_url').attr('href', terms1);
                $('#secondary_url').attr('href', terms2);

            } else if ($(this).is("#privacy")) {

                $('#primary_url').attr('href', privacy1);
                $('#secondary_url').attr('href', privacy2);
            }
        });
    }
};

I am trying to initialize the object above, and it does not work:

    Modal.init(

        contact1: "http:www.test1.com";
        contact2: "http:www.test2.com";
        aboutus1: "http:www.test3.com";
        aboutus2: "http:www.test4.com";
        privacy1: "http:www.test5.com";
        privacy2: "http:www.test6.com";
        terms1:   "http:www.test7.com";
        terms2:   "http:www.test8.com"

    );

Answers:

Answer

it is Done like this way,

i Guess this is what you want to do.

var Modal = {

    init: function (args) {

              //then access your values like this
            contact1=   args.contact1;
            contact2 = args.contact2;
            ..........
            .........
            .........
         }
}

And to initiate this method you have write as

Modal.init({
contact1:"contact str",
contact2:"contact str",
.....
.....
lastitem : "last str"
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.