/*
* 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. Vue.js路由组件

    1.如果在创建项目中,没有自动安装vue router,那就自行安装.cnpm install vue-router --save vue-router两种模式 hash模式和history模式. 默 ...

  2. WIN XP蓝屏代码大全

    转自:廊坊师范学院信息技术提高班---韩正阳 http://blog.csdn.net/jiudihanbing WIN XP蓝屏代码大全WIN XP蓝屏代码大全一.蓝屏含义 1.故障检查信息 *** ...

  3. Working with WordprocessingML documents (Open XML SDK)

    Last modified: January 13, 2012 Applies to: Office 2013 | Open XML This section provides conceptual ...

  4. C# JackLib系列之字体使用

    字体的使用一般我们都是使用系统字体,这样比较方便,直接 Font font=new Font("微软雅黑",16f,FontStyle.Bold); 但是当我们用到一个系统没有的字 ...

  5. 异步串行通信的XON与XOFF

    在单片机的异步串行通信中,putchar函数中的实现中反复用到了XON和XOFF,定义原型如下: #define XON 0x11#define XOFF 0x13 查找ASCII码表,这两个对应的是 ...

  6. delphi计算两个时间差

    uses DateUtils; var S1, S2: string; T1, T2: TDateTime; D, H, M, S: Integer; Value: Int64; begin S1 : ...

  7. ubuntu 下python安装及hello world

    //@desn:ubuntu 下python安装及hello world //@desn:码字不宜,转载请注明出处 //@author:张慧源  <turing_zhy@163.com> ...

  8. Linux服务器其中一个磁盘满了怎么办?在不做磁盘扩容的情况下,一个软连接就搞定。

    适用环境要求:Linux系统及服务器.有管理员权限.存在多余空间的磁盘例如下图中"/home"在磁盘sda5中与"/"不属于同一块磁盘: 1.首先转移正在使用的 ...

  9. C# WinForm Webbrowser 强制所有网页链接在同一页面打开或者在TabControl中弹出新窗口(续)

    上面那个文写的如同粑粑一样 效果图 Winfrom 中添加这个类就好了 using System; using System.Collections.Generic; using System.Com ...

  10. pycharm自动调整html页面代码缩进不正确的解决办法

    pycharm自动调整html页面代码缩进不正确的解决办法