在 javascript 中调用匿名函数
Call anonymous function in javascript
我知道这可能与某人相似,但我敢肯定,我还没有在这里找到答案,我只是想在变量中调用一个匿名函数,就像这样
me.req.ref['index']['index'] = function() {
var a, mount;
return {
function: function(fout) {
mount = new loading(fout, "flogin");
mount.start("Login granted, redirecting..");
a = setTimeout(function() {
window.location.href = purl+"profile";
}, 1000);
}
}
};
我想这样称呼它。
var ret;
ret = new me.req.ref[refcode][resp];
ret.function(fout);
但是显示错误。
Uncaught TypeError: ret is not a function
我在方法 loading()
中实现了它并且运行良好,这里是代码。
function loading(e, code) {
var x = 0;
return {
start: function(str) {
var dot, y;
dot = [".","..","...","...."];
y = 0;
e.style.height = "auto";
e.style.maxHeight = "100%";
e.innerHTML = str+dot[y]+" ("+x+")";
me.time.mount[code] = setInterval(function() {
e.innerHTML = str+dot[y]+" ("+x+")";
x++; y++;
if(y>3) {
y = 0;
}
}, 1000);
},
stop: function() {
clearInterval(me.time.mount[code]);
}
}
}
我叫loading()
的方式是这样的
mount = new loading(fout, me.time.code["flogin"]);
mount.start("string"); // if i want to start an loading.
mount.stop(); // if i want to shutdown the loading.
有什么解决办法吗?请帮忙。
感谢您的更正。
好吧,这里的问题是调用这样的方法 ret().function(fout)
,当 ret
是一个 Object
,所以这个问题已经解决,调用我需要的函数这样写ret.function(fout)
.
我知道这可能与某人相似,但我敢肯定,我还没有在这里找到答案,我只是想在变量中调用一个匿名函数,就像这样
me.req.ref['index']['index'] = function() {
var a, mount;
return {
function: function(fout) {
mount = new loading(fout, "flogin");
mount.start("Login granted, redirecting..");
a = setTimeout(function() {
window.location.href = purl+"profile";
}, 1000);
}
}
};
我想这样称呼它。
var ret;
ret = new me.req.ref[refcode][resp];
ret.function(fout);
但是显示错误。
Uncaught TypeError: ret is not a function
我在方法 loading()
中实现了它并且运行良好,这里是代码。
function loading(e, code) {
var x = 0;
return {
start: function(str) {
var dot, y;
dot = [".","..","...","...."];
y = 0;
e.style.height = "auto";
e.style.maxHeight = "100%";
e.innerHTML = str+dot[y]+" ("+x+")";
me.time.mount[code] = setInterval(function() {
e.innerHTML = str+dot[y]+" ("+x+")";
x++; y++;
if(y>3) {
y = 0;
}
}, 1000);
},
stop: function() {
clearInterval(me.time.mount[code]);
}
}
}
我叫loading()
的方式是这样的
mount = new loading(fout, me.time.code["flogin"]);
mount.start("string"); // if i want to start an loading.
mount.stop(); // if i want to shutdown the loading.
有什么解决办法吗?请帮忙。 感谢您的更正。
好吧,这里的问题是调用这样的方法 ret().function(fout)
,当 ret
是一个 Object
,所以这个问题已经解决,调用我需要的函数这样写ret.function(fout)
.