-
Notifications
You must be signed in to change notification settings - Fork 66
/
common.js
50 lines (44 loc) · 1.04 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$ns.copy = function (target /*, source ... */) {
if (target) {
for (var i = arguments.length - 1; i > 0; i --) {
var source = arguments [i];
if (source && source.hasOwnProperty) {
for (var key in source) {
if (source.hasOwnProperty (key)) {
target [key] = source [key];
}
}
}
}
}
return target;
};
$ns.is = function (object, type) {
var typeName = Object.prototype.toString.call (object).slice (8, -1);
return (
object !== undefined &&
object !== null &&
type.name === typeName
);
};
$ns.make = function (context, path) {
if ($is (context, String)) {
path = context;
context = document;
}
if (path) {
var paths = path.split ('.');
var key = paths.shift ();
context [key] = context [key] || {};
context = $make (context [key], paths.join ('.'));
}
return context;
};
$ns.define = function (context, path, object) {
$copy ($make (context, path), object);
};
$ns.assert = function (variable, value) {
if (variable != value) {
throw 'Assertion failed: ' + variable + ' != ' + value + '!';
}
};