[关闭]
@bornkiller 2014-08-25T09:34:05.000000Z 字数 1781 阅读 2440

AMDLocalstorage

javascript


AMDLocalstorage

Build Status

Analytics

AMD specific module for localstorage.

Purpose

Attention

Usage

  1. Put storage.js into your module directory or somewhere you want.
  2. Config the requirejs path.
  3. Import as dependency and do anything.
  1. require(['storage'], function (storage) {
  2. });

API

  1. // just storing something in localStorage
  2. storage.set('key','value');
  3. // getting that value
  4. storage.get('key');
  5. // remove that key
  6. storage.remove('key');
  7. // clear all localStorage values
  8. storage.clear();
  9. // just update stored things in localStorage
  10. storage.update('modifier', 'key', 'value');

About update method

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

  1. storage.set('love',1);
  2. storage.update('$inc','love',5);
  3. storage.get('love') == 6;
  1. storage.set('love',true);
  2. storage.update('$verse','love');
  3. storage.get('love') == false;
  1. storage.set('love',['first','first','first']);
  2. storage.update('$unique','love');
  3. storage.get('love') == ['first']
  1. storage.set('love',['first','second']);
  2. storage.update('$push','love','third');
  3. storage.get('love') == ['first','second','third']
  1. storage.set('love',{"title":"I love you","content":"I wish you were here"});
  2. storage.update('$extend','love',{"content":"Rock N roll","label":"dark"});
  3. storage.get('love') == {
  4. "title":"I love you",
  5. "content":"Rock N roll",
  6. "label":"dark"
  7. }

Schedual

Contact

Email: hjj491229492@hotmail.com

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注