zoukankan      html  css  js  c++  java
  • ES6 localStorage 类库

    无意中看到的,记录下。

    用到了es6语法。支持在js中写构造函数

    class CovLocalDB {
        constructor (name) {
            this.LS = null
            this.name = name
            this.checkLS()
            this.init(name)
        }
    
        checkLS () {
            if (window && window.localStorage) {
                this.LS = window.localStorage
                // console.log('localStorage is there?')
            } else {
                console.log('localStorage is there?')
            }
        }
    
        init (name) {
            if (this.LS) {
                if (this.LS[name]) {
                    this.data = JSON.parse(this.LS[name])
                } else {
                    this.data = {}
                }
            }
        }
    
        set (uri, data) {
            this.data[uri] = data
            if (this.LS) {
                this.LS[this.name] = JSON.stringify(this.data)
            }
        }
    
        get (uri) {
            if (this.data[uri]) {
                return this.data[uri]
            }
            return false
        }
    }
    
    
    const DB = new CovLocalDB('my-db')
    DB.set('name', 'finley');
    console.log(DB.get('name'));

    关于class

    class Point {
      constructor(){
        // ...
      }
    
      toString(){
        // ...
      }
    
      toValue(){
        // ...
      }
    }
    
    // 等同于
    
    Point.prototype = {
      toString(){},
      toValue(){}
    };

    参考:http://es6.ruanyifeng.com/#docs/class

  • 相关阅读:
    安装ArcGIS Server forJava
    MyEclipse编码设置
    地图切片公式备忘
    source
    逝去的痕迹
    flex build下的svn安装
    spket安装
    flex开发一
    vs2008中的SQL Server Express访问 sql server 2005
    导入不同格式的数据到arcgis中
  • 原文地址:https://www.cnblogs.com/mafeifan/p/5580908.html
Copyright © 2011-2022 走看看