Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140042

Receive JSON structured parameters in Javascript function

$
0
0

How to create a javascript function that will receive a JSON-like object as parameter, like this:

function foo() {
    //handle args somehow
}

And then be able to call it like this:

var someObj = {
    arg1: "some",
    arg2: "thing",
    options: {
        opt1: "asd",
        opt2: false
    }
}

foo(someObj);

Also, how to treat parameters that are not sent to the function (opt2 is omitted in this case):

var someObj = {
    arg1: "some",
    arg2: "thing",
    options: {
        opt1: "asd",
        //opt2: false
    }
}

foo(someObj);

Thanks.


Viewing all articles
Browse latest Browse all 140042

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>