从fis中得来的数据结构,Object版,
2017-01-10 15:29
274 查看
/* * config * caoke */ 'use strict'; //You can't use merge in util.js function merge(source, target){ if(typeof source === 'object' && typeof target === 'object'){ for(var key in target){ if(target.hasOwnProperty(key)){ source[key] = merge(source[key], target[key]); } } } else { source = target; } return source; } Object.prototype.hget = function(path, def){ var result = this || {}; (path || '').split('.').forEach(function(key){ if(key && (typeof result !== 'undefined')){ result = result[key]; } }); if(typeof result === 'undefined'){ return def; } else { return result; } } Object.prototype.hset = function(path, value){ if(typeof value === 'undefined'){ for(var k in path){ this[k]=path[k]; } } else { path = String(path || '').trim(); if(path){ var paths = path.split('.'), last = paths.pop(), data = this || {}; paths.forEach(function(key){ var type = typeof data[key]; if(type === 'object'){ data = data[key]; } else if(type === 'undefined'){ data = data[key] = {}; } else { console.error('forbidden to set property[' + key + '] of [' + type + '] data'); } }); data[last] = value; } } return this; } Object.prototype.hdel = function(path){ path = String(path || '').trim(); if(path){ var paths = path.split('.'), data = this, last = paths.pop(), key; for(var i = 0, len = paths.length; i < len; i++){ key = paths[i]; if(typeof data[key] === 'object'){ data = data[key]; } else { return this; } } if(typeof data[last] !== 'undefined'){ delete data[last]; } } return this; } Object.prototype.hmerge = function(){ var self = this; [].slice.call(arguments).forEach(function(arg){ if(typeof arg === 'object'){ merge(self, arg); } else { console.warning('unable to merge data[' + arg + '].'); } }); return this; } var sp={} sp.hset("user.name","caoke") sp.hset("user.qq","914890674") console.log(sp)
相关文章推荐
- AMF_OBJECT 数据结构浅析
- AMF_OBJECT 数据结构浅析
- PHP SPL标准库之数据结构对象容器(SplObjectStorage)
- Qt MetaObject 详解之二:QMeta数据以及数据结构信息
- Qt MetaObject System详解之二:meta数据和数据结构
- jSONObject数据结构和使用
- fis中的数据结构模块Config
- Ceph 基本数据结构(1)-object
- 驱动开发学习笔记01:DRIVER_OBJECT数据结构
- Android5.1.1数据结构解析之ObjectReference、StackReference
- 数据结构-二叉树
- FFMpeg 中比较重要的函数以及数据结构
- MOSS 2010:Visual Studio 2010开发体验(19)——ECMAScript Object Model(四)
- The Life Cycle of Hibernate entity object
- TypeError: Error #1034: 强制转换类型失败:无法将 Object@2555f679 转换为 mx.messaging.messages.IMessage。
- POJ 3367 Expressions(数据结构-二叉树)
- Android基础笔记——JSONObject方式解析JSON数据
- Java管理对象神奇之Object类的equals和hashcode
- git 错误 fatal: Not a valid object name: 'master'.
- 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file