如何将参数发送到自调用函数。喜欢以下代码。
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);
});
});
当我在我的js文件中添加此代码并运行Web应用程序时,它表示myId和myUrl没有定义并且没有运行js代码。
答案 0 :(得分:1)
看起来你真的想要这样做
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);
});
});