/*
* 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的更多相关文章

  1. Python 中的数据结构总结(一)

    Python 中的数据结构 “数据结构”这个词大家肯定都不陌生,高级程序语言有两个核心,一个是算法,另一个就是数据结构.不管是c语言系列中的数组.链表.树和图,还是java中的各种map,随便抽出一个 ...

  2. Python中的logging模块

    http://python.jobbole.com/86887/ 最近修改了项目里的logging相关功能,用到了python标准库里的logging模块,在此做一些记录.主要是从官方文档和stack ...

  3. Python 3 中的json模块使用

    1. 概述 JSON (JavaScript Object Notation)是一种使用广泛的轻量数据格式. Python标准库中的json模块提供了JSON数据的处理功能. Python中一种非常常 ...

  4. YII2 console中引用其他模块(子项目)的model时出现model找不到命名空间的问题解决

    YII2 console中写定时任务, 想使用其他模块的model, 在 console的yii.php 入口文件中引入其他模块的配置文件, 否者会出现model等命名空间找不到的问题. 还有, 命名 ...

  5. tensorflow中的gfile模块(转)

    简介 这些函数和python中的os模块非常的相似,一般都可以用os模块代替吧 gfile API介绍 下面将分别介绍每一个gfile API! 2-1)tf.gfile.Copy(oldpath, ...

  6. Python入门之Python中的logging模块

    基本用法 下面的代码展示了logging最基本的用法. import logging import sys # 获取logger实例,如果参数为空则返回root logger logger = log ...

  7. Python 中 logging 日志模块在多进程环境下的使用

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python 中 logging 日志模块在多进程环境下的使用 使用 Pytho ...

  8. 在ASP.NET MVC中创建自定义模块

    创建模块 module是实现了System.Web.IHttpModule接口的类.该接口定义了两个方法: Init:当模块初始化时被调用,传入的参数为HttpApplication对象,用于注册请求 ...

  9. openresty开发系列25--openresty中使用json模块

    openresty开发系列25--openresty中使用json模块 web开发过程中,经常用的数据结构为json,openresty中封装了json模块,我们看如何使用 一)如何引入cjson模块 ...

随机推荐

  1. Django--form基础

    一.Django--form功能 用户提交数据验证 生成html标签 二.基础实例 需求 利用Djang​o的form功能,接收用户注册信息. urls.py 1 2 3 4 5 from app01 ...

  2. Docker保存修改后的镜像

    1.启动镜像并做出修改 docker run -it centos /bin/bash [root@afcaf46e8305 /]# 注意afcaf46e8305是产生的容器ID,前面运行的时候不要- ...

  3. 关于wamp中升级PHP+Apache 的问题

    首先个人不建议wamp中升级php版本,如果你不信可以试一试,当你php升级后发想,奥,Apache版本不匹配,然后又去升级Apache,结果搞了半天,弄出来了就好,要是没出来,可能你会气死(好吧,气 ...

  4. 使用EasyUI,关于日期格式的文本框按照正常方式获取不到值的问题

    这是个小菜在实际工作中遇到的问题,相信很多EasyUI新手很可能也遇到这样的问题,因此小菜觉得有必要拿出来分享一下. 这个问题要从EasyUI的datebox组件说起,小菜用这个组件的时候,发现用$( ...

  5. Linux下面rpm命令和mount命令详解

    在Linux下面我们经常会安装一些软件包,还有挂载命令.接下来,我们通过一些实例来演示这些命令的使用.. 第一步:我们先在linux下面挂载光盘,先进入到根目录,然后切换到根下面的/mnt目录,因为/ ...

  6. MySQL性能调优与架构设计——第5章 备份与恢复

    第5章 备份与恢复 前言 数据库的备份与恢复一直都是 DBA 工作中最为重要的部分之一,也是基本工作之一.任何正式环境的数据库都必须有完整的备份计划和恢复测试,本章内容将主要介绍 MySQL数据库的备 ...

  7. C#分布式存储演练(提供项目下载)

    C#简单的演练了一下分布式的存储,学习fastdns的结构,Client向ProcessCenter请求Storage的服务,然后上传文件. 分布式服务就是多个服务器作为客户端互相[配合],要中心化就 ...

  8. curl下载目录

    http://ftp.loongnix.org/os/loongnix/1.0/SRPMS/ wget wget -c -r -np -k -L -p

  9. iOS No suitable application records were found. Verify your bundle identifier 'xxx' is correct.

    1.错误提示 打包工程,Validate 的时候提示: No suitable application records were found. Verify your bundle identifie ...

  10. Educational Codeforces Round 62 (Rated for Div. 2)E(染色DP,构造,思维,组合数学)

    #include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2 ...