[Project_owners] JSON and extensions

Nickolay Ponomarev asqueella at gmail.com
Sat Mar 4 04:46:24 EST 2006


On 3/4/06, Eric H. Jung <grimholtz at yahoo.com> wrote:
> I could do it easily only if I understood the code at http://www.json.org/json.js. I don't
> understand this syntax:
>
> var JSON = function () {
>   var m = {...},
>   ...,
>   return {
>     stringify: function (v) {}
>     };
> }();
>
> What the heck is that? That's about as comprehesible as http://www0.us.ioccc.org/2004/gavare.c
>
>
You're working with JS for quite a long time already; that syntax
shouldn't confuse you anymore. They are just using a closure to hide
their internal variables ("m") from the global scope. Those variables
are still accessible to methods of the object returned from the
anonymous function. The (function() {}) () syntax is understandable
too - they're declaring a function and calling it in one statement.

Nickolay


More information about the Project_owners mailing list