我有一个像这样初始化的JS库:
$("#container").mylibrary({
progressBarWidth: "480px",
fileUploadProgress: function(progress) {
// handle upload progress here
},
// etc. other callbacks and variables continue
)};
Run Code Online (Sandbox Code Playgroud)
我想改变它,以便我可以看到用户是否在移动设备上,如果是,则为进度条宽度返回不同的值.我怎样才能在这里输入一个小函数并返回一个值?我试过这个,没有运气:
progressBarWidth: (function() {
// do some math here
r = '480px';
return r;
}),
Run Code Online (Sandbox Code Playgroud)
您定义了该函数,但未执行该函数.您只需在其后添加括号即可自行执行匿名函数:
progressBarWidth: (function() {
// do some math here
r = '480px';
return r;
})()
Run Code Online (Sandbox Code Playgroud)