{Carrer web log}


Blog about web design & development

Using JavaScript Objects for storing data

Wednesday, September 14, 2011 { 2 Comments }

Few weeks ago I made "o - JS Library for Object Manipulation" and the next step was to build simple To Do app. The purpose this app was storing data into JavaScript object.

Why storing data into JS Objects?

Here are few motives:

- JavaScript objects have JSON like (key,value) structure that is perfect for storing data. You can store numbers, strings, arrays, other objects inside the Object value.

- Parsing the JavaScript Object is very fast in the new browsers.

- With JavaScript you can easily add, remove, extend and do other useful operation to the Object.

- The Object can be easily converted to JSON and vice versa.

- Via AJAX(AJAJ) you can send and receive JSON calls from the server.

- Native node.js support.

- Easy NoSql integration.

- Easy integration with the browser localStorage.

- We can change the browser application building logic by showing first the results to the user and then sending the data to the server(database). That will improve the User Experience and save some traffic because we will be sending/receiving just the JSON data of the actual change. Naturally this will bring new concerns like security, data synchronization and potential data loss.

I think we are not fully using the new browsers JavaScript engines. We can explore new ways and do the heavy lifting in the browser using the server just like permanent data storage.

Here is my simple To Do App that is using "o -library" for the object manipulation and jQuery for the DOM.The data are written only in the JS Object (for now). I used guid/uuid to generate random JavaScript object keys. I wrote a render function that will "render" all the values in the object. It is no so smart to render all the object values for any change made in the object but I'm doing it for purpose of this demo.

This technique is not new, with this post I don't want to reinventing the wheel just to simply point out the advantages of using Objects like data containers. I think many web application can use this approach that can save some serious web traffic.



To Do Link

The object will have this kind of structure:

var Obj = {
89fa0b75-ccc3-7491-df08-906088052575: "Buy milk",
3989d3db-40a5-5c58-4147-42a3cead4c94: "Make 30 Push Ups",
bc0e002e-09a7-d36b-ec6a-24462ea9486a: "Buy ice cream"
}

What do you think? I love to here your opinion.



2 Responses to “Using JavaScript Objects for storing data”

  1. // Anonymous Steven Bradley // 9/15/2011

    Vladimir it works well and is a good solution. At some point you would probably want to store things more permanently, but like you said the javascript object will talk easily to local html storage or directly to the server.  

  2. // Blogger Vladimir // 9/15/2011

    @Steven: The nice thing is that lot of developers are starting to use node.js the same code that run on the client can run on the server, and then saved to some NoSql DB.  

Post a Comment

<< Home

RSS IconTwitter icon Twitter icon Twitter icon

About Me <<<

Name: Vladimir Carrer
vladocar [at] gmail.com
Location: Verona, Italy
I'm a web designer, developer, teacher, speaker, generally web addicted ...

My projects <<<

§§Previous Posts <<<

Hand Drawn Icons
 

Other Profiles <<<

View Vladimir Carrer's profile on LinkedIn

Content is licensed under a Creative Commons Public Domain License