如何在IIFE语法js函数中使用参数返回函数
并在js外面调用
window.app = window.app || {};
window.app.test = app.test || {};
(function ($) {
var getResult = function (result) {
return result;
};
var handleError = function (result) {
return result.responseText;
};
//data: "{ 'fileName':'"+ fileName +"' }",
window.app.test.ReadFile = function (fileName) {
var FileContents = $.ajax({
type: "GET",
url: "~/helpers/FilesHelper.aspx/ReadAllContents",
data: JSON.stringify({ fileName: fileName }),
cache: false
});
FileContents.done(getResult).Fail(handleError);
};
}(jQuery));
我称之为
window.app.test.ReadFile( “helpers.txt”);
答案 0 :(得分:0)
您只需返回功能参考
即可window.app.test.ReadFile = (function ($) {
var getResult = function (result) {
return result;
};
var handleError = function (result) {
return result.responseText;
};
//data: "{ 'fileName':'"+ fileName +"' }",
return function (fileName) {
var FileContents = $.ajax({
type: "GET",
url: "~/helpers/FilesHelper.aspx/ReadAllContents",
data: JSON.stringify({
fileName: fileName
}),
cache: false
});
FileContents.done(getResult).fail(handleError);
};
}(jQuery));