JSTONE.js |
JSTONE.jsJavaScript Temporary Object Notation EngineJSTONE is a simple way to save temporary client informations. These informations should be every JSON compatible variable (Number, Boolean, null, Array, Object, String, Date) but with some simple hack these shuld be constructors, functions and other type of variables too. With JSTONE client doesn’t require cookies with value “0” as expiration date because every information will be available inside used window even if user refreshes the page. JSTONE doesn’t use Ajax to save informations so it’s compatible with every host. JSTONE simply allow developers to save temporary data that will not be lost on window update (refresh / F5) or using always the same window session. With JSTONE You can (using same browser window)
With JSTONE You can’t
To download last version of this script use this link: http://www.devpro.it/javascript_id_159.html Version
Compatibility
DependenciesJSTONE instances requires a generic JSON parser to encode/decode informations. You could use your favourite JSON parser sending encode and decode methods as first constructor argument. // Example: If you’ve not a JSON parser, You could use JSON.js one just sending them on JSTONE constructor. MyJSTONE = new JSTONE(JSON); AuthorAndrea Giammarchi, http://www.3site.eu LicenseCopyright (C) 2007 Andrea Giammarchi - www.3site.eu Summary
JSTONE
Create a JSTONE instance. You can create only one instance for each page. Arguments
NoteJavaScript is a scripting language parsed runtime and its native functions behaviour should be changed by malicious user. It’s a good practice to don’t save private data/informations inside cookies and in this case should be a good practice don’t save these kind of informations inside JSTONE too. Please remember that JSTONE is based on window.name property and everyone, from every site, should read this property parsing them using JSON. This is another reason to don’t believe on JSTONE object for personal data or private informations even if You use last clear argument to remove every information from window.name property. clear
destroy every private object information. ExampleMySTONE = new JSTONE(JSON); Example [paranoia version]// using server side informations, in this case a PHP session id NoteMalicious users should set window.name in their pages manually adding other site parameters. This check should be based on server-side informations such session ID. If generic STONE.read(“SID”) is different, session was expired or user doesn’t come from your site. In this way You can have better and more secure (just a bit) control with your JSTONE instance. read
try to find a variable and return its value or undefined. Arguments
Returns
Example 1MySTONE = new JSTONE(JSON); Example 2MySTONE = new JSTONE(JSON); NoteJSTONE search function creates automatically empty objects before last searched value if these are not defined. If You search “user.name”, for example, “user” namespace will be created automatically. write
set a generic variable into selected namespace Arguments
ExampleMySTONE = new JSTONE(JSON); NoteJSTONE search function creates automatically empty objects before last namespace value if these are not defined. Namespace uses dot convention “.” to separate each value. PrivateList
|
Create a JSTONE instance.
function JSTONE( JSON, free, clear )
destroy every private object information.
this.clear = function()
try to find a variable and return its value or undefined.
this.read = function( key )
set a generic variable into selected namespace
this.write = function( key, value )