Repository navigation
Expand file tree
/
Copy pathobjectFunctions.js
More file actions
71 lines (66 loc) · 1.76 KB
/
Copy pathobjectFunctions.js
File metadata and controls
71 lines (66 loc) · 1.76 KB
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
70
71
/*@objectFunctions.js
Injects helper functions into 'J' to help with object manipulation.
*/
(function (J) {
"use strict";
var JObject = new J.Class();
JObject.prototype.init = function (variable) {
if (this.isObject(variable)) {
this.obj = variable;
}
};
/*@objectIsObject
Verifies variable is an Object.
*/
JObject.prototype.isObject = function (variable) {
if (!!variable && typeof variable !== typeof {}) {
return false;
}
return true;
};
/*@objectIsEmpty
Use object keys if possible, else use iterative method.
*/
JObject.prototype.isEmpty = function () {
var prop;
if (!!Object.keys) {
if (Object.keys(this.obj).length !== 0) {
return false;
}
} else {
for (prop in this.obj) {
if (this.obj.hasOwnProperty(prop)) {
return false;
}
}
}
return true;
};
/*@clone
Merge Objects together, allowing for object defaults.
*/
JObject.prototype.clone = function () {
var obj = {};
for (var key in this.obj) {
obj[key] = this.obj[key];
}
return obj;
};
/*@merge
Merge Objects together, allowing for object defaults.
*/
JObject.prototype.mergeWith = function (obj, overwrite) {
for (var key in obj) {
if (!this.obj.hasOwnProperty(key) || !!overwrite) {
this.obj[key] = obj[key];
}
}
return this.obj;
};
/*@J.object
objectFunction entry point.
*/
J.object = function (obj) {
return new JObject(obj);
};
}(window.J));