-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.js
34 lines (31 loc) · 984 Bytes
/
common.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
/**
* Helper function to define namespaces.
*
* Note: As a convention, Namespaces should be capitalized and classes
* should begin with a lowercase.
*
* @param String type A . seperated list of namespaces. "Example.My.Hierarchy"
* @param mixed value Value for the type. A callback.
*/
function typedef (type, value) {
var namespaces = [],
scope = window,
name = '';
if (typeof value === typeof function () {} ) {
value = value.call();
};
if (typeof (type) == 'string') {
namespaces = type.split('.');
for (var i = 0; i < namespaces.length; i++) {
name = namespaces[i];
if ( typeof (scope[name]) == 'undefined') {
if ( (i+1) == namespaces.length && value !== undefined ) {
scope[name] = value;
} else {
scope[name] = {};
}
}
scope = scope[name];
}
}
}