1

I know this could be similiar with someone, but i'm sure, i'm not yet found the answer here, i just want to call an anonymous function in a variable, which like this

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);
        }
    }
};

and i want to call it like this.

var ret;

ret = new me.req.ref[refcode][resp];
ret.function(fout);

but it show an error.

Uncaught TypeError: ret is not a function

i implement this in method loading() and work well, here the code.

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]);
        }
    }
}

the way that i call loading() is like this.

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.

any solution? please help. thanks for any correction.

8
  • 1
    Are you sure this is the error you are getting? You are calling ret nowhere in the shown code. Also, should you do so, it would be obvious, as ret is supposed to be an object, right? Commented Aug 8, 2018 at 2:18
  • There's technically nothing wrong with the way you are calling the function, it should work so long as the ret object actually has the key function on it which is bound to a function. When you debug it, is the ret object defined? is ret.function defined? In your first code block, you are binding to me.req.ref['index']['index'], when you call it are refcode and resp equal to 'index'? Commented Aug 8, 2018 at 2:22
  • @ASDFGerta correct, but when i call it is said not a function. Commented Aug 8, 2018 at 2:27
  • @SimonK the code block is already consecutive. Sure, the refcode and resp is the 'index'. Commented Aug 8, 2018 at 2:28
  • But ret is not supposed to be a function, from your code, ret should be an object, with a property called "function", which is a function. That's why you do ret.function(fout); - i don't understand. Commented Aug 8, 2018 at 2:29

1 Answer 1

1

Alright, the problem in here is calling the method like this ret().function(fout), when the ret is an Object, so this problem answered, to call the function i need to write it like this ret.function(fout).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.