fis中的数据结构模块Config
/*
* config
* caoke
*/ 'use strict';
Object.extend=function(props){
//继承父类
var prototype=Object.create(this.prototype)
//初始化函数ctor
var _Class=function(){
if(arguments.length>0){
var sp=new _Class()
if (sp.constructor){
sp.constructor.apply(sp, arguments);
}
return sp;
} }
//当前类属性和方法
for(var k in props){
prototype[k]= props[k]
}
_Class.prototype = prototype;
//类继承
_Class.extend=this.extend;
//类扩展
_Class.expand = function (prop) {
for (var name in prop) {
prototype[name] = prop[name];
}
};
return _Class
} //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;
} var Config = Object.extend({
constructor : function(){
this.init.apply(this, arguments);
},
init : function(){
this.data = {};
if(arguments.length > 0){
this.merge.apply(this, arguments);
}
return this;
},
get : function(path, def){
var result = this.data || {};
(path || '').split('.').forEach(function(key){
if(key && (typeof result !== 'undefined')){
result = result[key];
}
});
if(typeof result === 'undefined'){
return def;
} else {
return result;
}
},
set : function(path, value){
if(typeof value === 'undefined'){
this.data = path;
} else {
path = String(path || '').trim();
if(path){
var paths = path.split('.'),
last = paths.pop(),
data = this.data || {};
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;
},
del : function(path){
path = String(path || '').trim();
if(path){
var paths = path.split('.'),
data = this.data,
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;
},
merge : function(){
var self = this;
[].slice.call(arguments).forEach(function(arg){
if(typeof arg === 'object'){
merge(self.data, arg);
} else {
console.warning('unable to merge data[' + arg + '].');
}
});
return this;
}
}); module.exports = Config;
fis中的数据结构模块Config的更多相关文章
- Python 中的数据结构总结(一)
Python 中的数据结构 “数据结构”这个词大家肯定都不陌生,高级程序语言有两个核心,一个是算法,另一个就是数据结构.不管是c语言系列中的数组.链表.树和图,还是java中的各种map,随便抽出一个 ...
- Python中的logging模块
http://python.jobbole.com/86887/ 最近修改了项目里的logging相关功能,用到了python标准库里的logging模块,在此做一些记录.主要是从官方文档和stack ...
- Python 3 中的json模块使用
1. 概述 JSON (JavaScript Object Notation)是一种使用广泛的轻量数据格式. Python标准库中的json模块提供了JSON数据的处理功能. Python中一种非常常 ...
- YII2 console中引用其他模块(子项目)的model时出现model找不到命名空间的问题解决
YII2 console中写定时任务, 想使用其他模块的model, 在 console的yii.php 入口文件中引入其他模块的配置文件, 否者会出现model等命名空间找不到的问题. 还有, 命名 ...
- tensorflow中的gfile模块(转)
简介 这些函数和python中的os模块非常的相似,一般都可以用os模块代替吧 gfile API介绍 下面将分别介绍每一个gfile API! 2-1)tf.gfile.Copy(oldpath, ...
- Python入门之Python中的logging模块
基本用法 下面的代码展示了logging最基本的用法. import logging import sys # 获取logger实例,如果参数为空则返回root logger logger = log ...
- Python 中 logging 日志模块在多进程环境下的使用
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python 中 logging 日志模块在多进程环境下的使用 使用 Pytho ...
- 在ASP.NET MVC中创建自定义模块
创建模块 module是实现了System.Web.IHttpModule接口的类.该接口定义了两个方法: Init:当模块初始化时被调用,传入的参数为HttpApplication对象,用于注册请求 ...
- openresty开发系列25--openresty中使用json模块
openresty开发系列25--openresty中使用json模块 web开发过程中,经常用的数据结构为json,openresty中封装了json模块,我们看如何使用 一)如何引入cjson模块 ...
随机推荐
- 19、SOAP安装,运用与比对结果解释
转载:http://www.dengfeilong.com/post/Soap2.html https://blog.csdn.net/zhu_si_tao/article/details/71108 ...
- cgroup初步分析(1)
cgroup的功能和作用不废话,直说一下cgroup的几条设计准则,有了几条设计准则的约束,就比较容易理解其中的数据结构和函数,至于源代码cgroup.c,无非是两个内容,一是task_struct. ...
- Vim编码知识,乱码问题
原文:http://demi-panda.com/2012/12/26/vim-encoding/ 在vim的初始学习阶段,乱码经常是困扰新手的一个比较烦躁的问题,本文试图阐述Vim的编码知识,及设置 ...
- 【Android学习】自定义checkbox
1.1 自定义checkbox 选中图片 自定义checkbox使用的时android:background而不是android:button,原因在于使用button时自定义图片过大超出边缘部分会截 ...
- C#Thread学习
一.Thread的使用方式 1.不带参数 (1)使用lambda public static void fun1() { Console.WriteLine($"Main ThreadId: ...
- Android日期时间选择器DatePicker、TimePicker日期时间改变事件响应(Android学习笔记)
activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- go channel缓冲区的大小
go channel缓冲区的大小 len也可以作用于channel,代表现在channel缓冲区中还有多少数据没有读取.示例如下 c:=make(chan int,20) fmt.Println(&q ...
- spring @Async 线程池使用
最近公司项目正逐渐从dubbo向springCloud转型,在本次新开发的需求中,全部使用springcloud进行,在使用时线程池,考虑使用spring封装的线程池,现将本次使用心得及内容记录下来 ...
- ecliplse启动慢的优化方法(亲测有效)
本人使用的ecliplse IDE 版本是: Version: Photon Release (4.8.0)Build id: 20180619-1200 我的电脑配置是 Ecliplse启动差不多一 ...
- 关于小程序bindregionchange事件在IOS崩溃的问题
先说下原因,我在bindregionchange事件触发函数中设置了经纬度,而latitude和longitude是绑定在map组件上的,滑动地图的过程中重新设置了地图中心点的经纬度,会导致地图本身的 ...