-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfiguration.js
70 lines (61 loc) · 1.81 KB
/
Configuration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var Configuration = (function(CONFIG) {
var self = new Object();
/**
* Get a value from an object or array.
* @param {object|array} subject
* @param {string} key
* @param {*} dfault
* @returns {*}
*/
self.prototype.get = function( key, dfault ) {
var value = dfault;
if (this.hasOwnProperty(key)) {
value = this[key];
}
return value;
};
/**
* Get a value from an object or array.
* @param {object|array} subject
* @param {string} key
* @param {*} dfault
* @returns {*}
*/
self.prototype.set = function( key, value ) {
this[key] = value;
};
/**
* Extends {Object} target with properties from {Object} source.
* @param target
* @param source
*/
self.prototype.extend = function(source) {
for (var key in source) {
if (this.get(key, false)) {
continue;
}
this[key] = source[key];
}
};
/**
* Updates {Object} target with properties from {Object} source.
* Any previously set values will be over-written.
* @param {Object} source The source object with new values.
* @param {Boolean} overwrite Whether or not new values should replace old values.
*/
self.prototype.update = function(source, overwrite) {
if (typeof(overwrite) == undefined) {
overwrite = true;
}
for (var key in source) {
if (this.hasOwnProperty(key)) {
if (! overwrite && this.get(key, false)) {
continue;
}
this[key] = source[key];
}
}
};
self.extend(CONFIG);
return self;
}(CONFIG || {}));