sending parameters to self invoking functions

104 views Asked by At

How do I send parameters to self invoking functions. like following code.

MyNameSpace.Administration.WebAdministrator = function () {
    var init = function () {
      //some code here
    },
    CreateSubSite = function (id, url) {
     //some code here
    }
    return {
    start: function () {
        init();
    },
    createSubSite: CreateSubSite(myId, myUrl)
}();

$(document).ready(function () {
    MyNameSpace.Administration.WebAdministrator.start();
    $("div.large-app").on("click", "#btnCreate", function () {
       var id = "something";
       var url = "something";
       MyNameSpace.Administration.WebAdministrator.createSubSite(id, url);
    });
});

When I add this code on my js file and run the web application it says myId and myUrl not defind and not runing the js code.

1

There are 1 answers

0
adeneo On BEST ANSWER

Looks like you're really trying to do this

var MyNameSpace = {
    Administration : {
        WebAdministrator : {
            init : function () {
              //some code here
            },
            CreateSubSite : function (id, url) {
             //some code here
            },
            start : function () {
                this.init(); // really ?
            }
        }
    }
};

$(document).ready(function () {
    MyNameSpace.Administration.WebAdministrator.start();
    $("div.large-app").on("click", "#btnCreate", function () {
       var id = "something";
       var url = "something";
       MyNameSpace.Administration.WebAdministrator.CreateSubSite(id, url);
    });
});

FIDDLE