@bornkiller
2014-08-25T09:34:05.000000Z
字数 1781
阅读 2440
javascript
AMD specific module for localstorage.
storage.js
into your module directory or somewhere you want.
require(['storage'], function (storage) {
});
// just storing something in localStorage
storage.set('key','value');
// getting that value
storage.get('key');
// remove that key
storage.remove('key');
// clear all localStorage values
storage.clear();
// just update stored things in localStorage
storage.update('modifier', 'key', 'value');
modify | feature |
---|---|
$inc |
to plus a number for the stored value |
$verse |
to verse a boolean for the stored value |
$unique |
unique the stored array,the third argument not in need |
$push |
to push new value into the stored array(array and other variable type acceptalbe) |
$extend |
to update the stored object with particular object |
For example
storage.set('love',1);
storage.update('$inc','love',5);
storage.get('love') == 6;
storage.set('love',true);
storage.update('$verse','love');
storage.get('love') == false;
storage.set('love',['first','first','first']);
storage.update('$unique','love');
storage.get('love') == ['first']
storage.set('love',['first','second']);
storage.update('$push','love','third');
storage.get('love') == ['first','second','third']
storage.set('love',{"title":"I love you","content":"I wish you were here"});
storage.update('$extend','love',{"content":"Rock N roll","label":"dark"});
storage.get('love') == {
"title":"I love you",
"content":"Rock N roll",
"label":"dark"
}
Email: hjj491229492@hotmail.com