Loading ...
Sorry, an error occurred while loading the content.

91Re: [json] JSON as a function parameter

Expand Messages
  • Michal Migurski
    Aug 20, 2005
    • 0 Attachment
      > [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

      I use this method in my PHP work pretty often, especially when
      consuming GET or POST vars, or instantiating objects which have a mix
      of required and optional arguments. Some languages have explicit
      support for this sort of use, such as Python:

      def f(**kwargs):
      print kwargs['msg']

      # prints "hello world"
      f(msg='hello world')

      Ronny is right - there is no JSON parsing overhead in what you're
      doing, because you are passing plain old javascript object literals.
      http://developer.mozilla.org/en/docs/
      Core_JavaScript_1.5_Guide:Literals#Object_Literals

      ------------------------------------------------------
      michal migurski- contact info, blog, and pgp key:
      sf/ca http://mike.teczno.com/contact.html
    • Show all 4 messages in this topic