frequent
frequent

Reputation: 28513

how to set a variable through a function call in Jquery?

I want to set a variable by running a function and retrieving a value.

This is my code (abbreviated if-checks):

var setToPage  = return loopHistory("external");

function loopHistory(scope) {
    for (var i = $.mobile.urlHistory.stack.length-2; i>=0; i--) {

        if (scope == "internal" ){
            if ( some[i] == thing ) || i == 0  ) {
                i == 0 ?  $temp =  "VALUE-ONE" : $temp =  "VALUE-TWO"
                return $temp;
                break;
                }
            } else if (scope == "external") {
                $temp = some[i];
                if ( thing == true )  {
                    return $temp;
                    break;
                    }
                }
        }
    }

This does not work.

Question:
How do I declare the value of setToPage by running the function above?

Thanks for help!

Upvotes: 0

Views: 275

Answers (1)

Marc B
Marc B

Reputation: 360782

I don't know what the point of the return on your first line is... return is for inside a function, to return a value to whatever called the function.

var setToPage  = loopHistory("external");

Upvotes: 3

Related Questions