Walking on JavaScript objects trees. Can we do it with JSON or JavaScript like we can while we work with XML?
Due to this, casual instance of JavaScript object often contains reference to another JavaScript objects instances and these (or different) instances, may, in turn, include references to that instance.
Taking into consideration this fact, it’s quite easy to imagine some tree of graph of inter-related JavaScript objects exist on runtime.
Of course, as soon as we have objects, we’d like to do something with them (and usually developers write code which performs various manipulations over JavaScript objects).
While there are many custom algorithms and manipulations, which can be need (at least, we are talking about the logic which makes your page unique), there are still many common, repetitive but necessary tasks which are performed as part of everyday development activity.
For example, data copying, populating, validating, merging objects data and so on. They are not fun, but they are really should be performed to bring your application to life.
Sure thing, each operation and each piece of code that does something with object instance can be considered as something unique and exceptional one. The only drawback of this – lots of quite boring, stupid and error-prone code occurs.
Ok, but what could be done to eliminate that? Oh, let’s think about it… But first try to look at the JavaScript objects from another point of view.
What is JavaScript object? Well, the question answers itself – it’s object. Object is the foundation of Object-Oriented programming and contains data with methods which allow performing manipulations over these data. Let’s try to concentrate on the first part of “object” form definition – data. Do we know something similar to this (please note that we don’t consider single instance of object there – but the entire object graph)? Yes, surprisingly, XML (or rather abstraction of data storing in XML) is quite close.
Ok, we are close so far but it’s not clear how we can simplify writing common repetitive code which, for example, populates HTML form by underlying model represented by tree of JavaScript objects (mind the JSON!)?
In both cases, XML parser makes for us all dirty work of parsing initial XML (reading incoming streams, manipulating characters, insuring proper string encoding) and so on. DOM parser provides us in-memory presentation of original XML as set of objects with well defined interface, while SAX let us obtain information about XML via set of events (like element start, element stop etc) generated by SAX parser via appropriate callbacks we provide to it.
An event-based API reports parsing events (such as the start and end of JSON node) directly to the application through callbacks. In both cases, an event-based API provides simpler, lower-level and uniform access to data structure represented by JavaScript objects.
Unlike SAX, which is not applicable for changing data, JSON event-based API can be used not only to get unified access to JavaScript objects, but also to manipulate them (for example, by changing particular attributes or even changing structure) since it works with complete objects stored in memory.
Since JSONER performs all behind-the-scene operations necessary to traverse elements of objects graph, developer is free from it and needs to write code that performs only particular specific functions. That code is placed to appropriate callback function which will be invoked by JSONER.
In general, having unified algorithm of working with objects allows simplifying code and separate business logic required to implement specific tasks and, as result, to increase overall code flexibility.
Yes, that’s true. But if JSONER library handles cross-links correctly – should we really think about this too much?
Oh, and finally, JSONER is free and opensource - so it's naturally that you can find that project on SourceForge!
Track back from
Thanks for the link!
I favourite one is jQuery
I would also recommend
Good collection. Especially
Once you've read Martin
Thanks, It worked .
Really
thanx but actually i need a
please send me the tutorial
This tutorial is a really
does in long stay system xanax with been white
purchase xanax Can kind baby
overnight xanax a be who
pregnancy xanax can million and
xanax com