JSON as a function parameter

J

Java script Dude

I have been spending building a great deal of complex Product/Business
workflow wizards and tools that are required to handle tons of data and
great deal of client side functionality.

As a result, many functions and methods have gotten to require longer
and longer set of parameters. The worst case yet is about 12 parameters
with some being optional. In these cases, the calling code gets more
and more un-readable as you add args. Also optional entries must have
null ("") values all over the place making for unneeded code.

With my ultimate goal of having clean and maintainable code, I have
started using on object using json to pass the parameters and data to
the function/method.

before:
.. obj.init(
.. . "My Type","My Name","n",true, false...
.. )

after:
.. obj.init({
.. . type: "My Type", name: "My Name", rev: "n", doThis: true, doThat:
false...
.. })

Has anybody conducted or seen tests on the performance of this json
method vs regular calls.

[Notes]

[Advantages]
.. Cleaner calling code
.. Flexible calling API
.. Somewhat cleaner callee code from visually implied namespace (j.arg1)
.. Tightened API calls:
.. . obj.myMethod = function Obj_myMethod(j){// (singleton)
.. . . . if(!isJSON(j)){debugErr("j must be a JSON")}
.. . }
.. JSON variable can be easily passed around

[Disadvantages]
.. Overall size of the calling code is a little larger
.. Hit on interpreter performance to parse json
.. Null value parameter assertions require additional code

..:JsD:.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top