Class StorableObject
StorableObject is an object that can be persisted between requests.
Defined in: <lib\storage.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
StorableObject(obj)
A StorableObject is an object that can be persisted between requests. |
| Field Attributes | Field Name and Description |
|---|---|
| <static> |
StorableObject.id
The id of a StorableObject is auto-generated and can't be changed.
|
A StorableObject is an object that can be persisted between requests.
To create a StorableObject, call new StorableObject().
You can optionally pass any JavaScript object to the constructor, and the
properties and values of the object will become properties and values
of the newly-created StorableObject, as in
new StorableObject({username: "aiba", password: "sex"}).
StorableObjects are very similar to normal JavaScript objects, except that
StorableObjects can't have properties that are functions. Properties that
are objects must be StorableObjects, and assigning a normal JavaScript object
will cause a StorableObject to be created (in other words, storage.foo
= {a: 1} behaves like storage.foo = new StorableObject({a: 1})).
Once a StorableObject is constructed, it may be persisted in two different
ways: You can assign it as the property of another StorableObject, such as
the root StorableObject called storage. Or you can add it
to a StorableCollection.
// Storing a string var obj = new StorableObject(); obj.message = "Hi there!"; storage.foo = obj;
// Alternative code to do the same thing
storage.foo = new StorableObject({message: "Hi there!"});
// Adding StorableObjects to a StorableCollection
storage.people = new StorableCollection();
var person1 = new StorableObject({name: "Aaron", age: 25});
var person2 = new StorableObject({name: "David", age: 24});
var person3 = new StorableObject({name: "JD", age: 25});
storage.people.add(person1);
storage.people.add(person2);
storage.people.add(person3);
- Parameters:
- {object} obj Optional
- An optional object
whose properties will be copied into the returned
StorableObject.
objcannot have any functions, and any properties ofobj's prototype are ignored. Any objects thatobjreferences will also be copied. (Note that because properties are copied, any subsequent modifications toobjwill not be reflected in the returned StorableObject).
getStorable.