forked from jashkenas/underscore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunderscore.extensions.js
More file actions
67 lines (53 loc) · 1.71 KB
/
underscore.extensions.js
File metadata and controls
67 lines (53 loc) · 1.71 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
(function(window, _, undefined){
function emptyFn(){}
window.console = (function() {
var m = ['log', 'error', 'info', 'warn', 'time', 'timeEnd', 'dir'],
c = {}, i = 0, l = m.length;
if (window.console !== undefined) {
return window.console;
}
for (; i < l; i++) {
c[m[i]] = emptyFn;
}
return c;
})();
_.isNumeric = function isNumeric(n) {
return !isNaN(parseInt(n, 10)) && isFinite(n);
};
_.extend = function extend() {
/*
* deep recursion, no limit
* likely breaks in many scenarios, only use for raw objects.
* currently doesn't merge arrays, overwrites
*
* Interesting discussion about deep recursion here:
* https://github.com/documentcloud/underscore/issues/162
*
*/
var typeOf = Object.prototype.toString,
target = arguments[0] || {},
len = arguments.length,
i = 0,
options,
name,
src,
copy;
for (; i < len; i++) {
if ((options = arguments[i]) !== null) {
for (name in options) {
src = target[name];
copy = options[name];
if (target === copy) {
continue;
}
if (copy && typeOf.call(copy) === '[object Object]') {
target[name] = extend(src, copy);
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
return target;
};
})(this, this._);